List of usage examples for org.apache.commons.io FilenameUtils getName
public static String getName(String filename)
From source file:de.uzk.hki.da.grid.IrodsCommandLineConnector.java
/** * Gets checksum from ICAT for the newest instance destDao * @author Jens Peters//from w w w.ja v a2 s .c o m * @param destDao * @return */ public String getChecksumOfLatestReplica(String destDao) { String ret = ""; String commandAsArray[] = new String[] { "ils -L", destDao }; String out = executeIcommand(commandAsArray); if (out.indexOf("ERROR") >= 0) throw new RuntimeException(" Get Checksum of " + destDao + " failed !"); Scanner scanner = new Scanner(out); String data_name = FilenameUtils.getName(destDao); while (scanner.hasNextLine()) { String line = scanner.nextLine(); if (line.contains(data_name)) { ret = line.substring(38, line.length()); } } scanner.close(); return ret; }
From source file:com.alibaba.otter.node.etl.load.loader.db.FileLoadAction.java
private void dryRun(FileLoadContext context, List<FileData> fileDatas, File rootDir) { for (FileData fileData : fileDatas) { boolean isLocal = StringUtils.isBlank(fileData.getNameSpace()); String entryName = null;/*from ww w . j ava2s . com*/ if (true == isLocal) { entryName = FilenameUtils.getPath(fileData.getPath()) + FilenameUtils.getName(fileData.getPath()); } else { entryName = fileData.getNameSpace() + File.separator + fileData.getPath(); } File sourceFile = new File(rootDir, entryName); if (true == sourceFile.exists() && false == sourceFile.isDirectory()) { if (false == isLocal) { throw new LoadException(fileData + " is not support!"); } else { // meta? fileData.setSize(sourceFile.length()); fileData.setLastModifiedTime(sourceFile.lastModified()); context.getProcessedDatas().add(fileData); } LoadCounter counter = loadStatsTracker.getStat(context.getIdentity()).getStat(fileData.getPairId()); counter.getFileCount().incrementAndGet(); counter.getFileSize().addAndGet(fileData.getSize()); } else if (fileData.getEventType().isDelete()) { // if (false == isLocal) { throw new LoadException(fileData + " is not support!"); } else { context.getProcessedDatas().add(fileData); } } else { context.getFailedDatas().add(fileData);// } } }
From source file:com.sun.portal.portletcontainer.driver.admin.UploadServlet.java
private String processFileItem(FileItem fi) throws FileUploadException { // On some browsers fi.getName() will return the full path to the file // the client select this can cause problems // so the following is a workaround. try {/*from w ww. j av a 2 s .c om*/ String fileName = fi.getName(); if (fileName == null || fileName.trim().length() == 0) { return null; } fileName = FilenameUtils.getName(fileName); File fNew = File.createTempFile("opc", ".tmp"); fNew.deleteOnExit(); fi.write(fNew); File finalFileName = new File(fNew.getParent() + File.separator + fileName); if (fNew.renameTo(finalFileName)) { return finalFileName.getAbsolutePath(); } else { // unable to rename, copy the contents of the file instead PortletWarUpdaterUtil.copyFile(fNew, finalFileName, true, false); return finalFileName.getAbsolutePath(); } } catch (Exception e) { throw new FileUploadException(e.getMessage()); } }
From source file:loci.formats.in.IonpathMIBITiffReader.java
@Override protected void initMetadataStore() throws FormatException { super.initMetadataStore(); MetadataStore store = makeFilterMetadata(); int simsIndex = seriesTypes.get("SIMS"); String instrument = (String) simsDescription.get("mibi.instrument"); store.setInstrumentID(formatMetadata("Instrument", instrument), simsIndex); store.setImageDescription((String) simsDescription.get("mibi.description"), simsIndex); String currentFile = FilenameUtils.getName(this.getCurrentFile()); for (Map.Entry<String, Integer> entry : seriesTypes.entrySet()) { String key = entry.getKey(); if (key != null) { store.setImageID(formatMetadata("Image", entry.getKey()), entry.getValue()); store.setImageName(currentFile + " " + entry.getKey(), entry.getValue()); }//from www . j a va 2 s . com } for (int j = 0; j < channelIDs.size(); j++) { store.setChannelID(formatMetadata("Channel", channelIDs.get(j)), simsIndex, j); if (channelNames.get(j) != null) { store.setChannelName(formatMetadata("Target", channelNames.get(j)), simsIndex, j); } } }
From source file:com.abiquo.am.services.TemplateConventions.java
private static String normalizeFileHref(final String filehref) { if (filehref.startsWith("http://")) { return FilenameUtils.getName(filehref); } else/*from ww w.j a v a 2 s . c om*/ // already relative to package { return filehref; } }
From source file:Controladores.ControladorCargaSolicitudes.java
public boolean save() { String filename;/*from w w w . j av a 2s . c o m*/ InputStream input = null; OutputStream output = null; boolean cargaExitosa = false; try { if (archivo.getFileName().endsWith(".txt") || archivo.getFileName().endsWith(".csv")) { filename = FilenameUtils.getName(archivo.getFileName()); input = archivo.getInputstream(); output = new FileOutputStream(new File("/home/root2/files", filename)); IOUtils.copy(input, output); cargaExitosa = true; } else { FacesUtils.showFacesMessage( "El archivo no ha sido cargado con xito. Verifique que el archivo tenga la extension txt", 1); } } catch (IOException ex) { Logger.getLogger(ControladorSolicitud.class.getName()).log(Level.SEVERE, null, ex); FacesUtils.showFacesMessage( "El archivo no ha sido cargado con xito. Verifique que el archivo tenga la extension txt", 1); } finally { IOUtils.closeQuietly(input); IOUtils.closeQuietly(output); } return cargaExitosa; }
From source file:com.sisrni.managedbean.NoticiaMB.java
public void uploadListener(FileUploadEvent event) { FacesContext facesContext = FacesContext.getCurrentInstance(); ExternalContext externalContext = facesContext.getExternalContext(); HttpServletResponse response = (HttpServletResponse) externalContext.getResponse(); String fileName = FilenameUtils.getName(event.getFile().getFileName()); String fileNamePrefix = FilenameUtils.getBaseName(fileName) + "_"; String fileNameSuffix = "." + FilenameUtils.getExtension(fileName); File uploadFolder = new File("/var/webapp/uploads"); try {//from w w w . j a v a 2 s .com File result = File.createTempFile(fileNamePrefix, fileNameSuffix, uploadFolder); if (fileNameSuffix.equalsIgnoreCase(".png") || fileNameSuffix.equalsIgnoreCase(".jpg")) { fileForFb = result; //para publicar en fb } FileOutputStream fileOutputStream = new FileOutputStream(result); byte[] buffer = new byte[1024]; int bulk; InputStream inputStream = event.getFile().getInputstream(); while (true) { bulk = inputStream.read(buffer); if (bulk < 0) { break; } fileOutputStream.write(buffer, 0, bulk); fileOutputStream.flush(); } fileOutputStream.close(); inputStream.close(); String value = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("formNoticia:editor_input"); if (".pdf".equals(fileNameSuffix) || ".doc".equals(fileNameSuffix)) { if (".pdf".equals(fileNameSuffix)) { noticia.setContenido(value + "<a data-toggle=\"tooltip\" title=\"" + fileName + "\" href=\"/project/images/" + result.getName() + "\">" + "<img style=\"width:50px;height:60px\" src=\"/project/images/pdf.png" + "\" />" + "</a>"); } else { noticia.setContenido(value + "<a data-toggle=\"tooltip\" title=\"" + fileName + "\" href=\"/project/images/" + result.getName() + "\">" + "<img style=\"width:50px;height:60px\" src=\"/project/images/doc.png" + "\" />" + "</a>"); } } else { noticia.setContenido(value + "<img style=\"width:100%;max-width:1000px\" src=\"/project/images/" + result.getName() + "\" />"); } RequestContext.getCurrentInstance().update("formNoticia:editor_input"); FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " ha sido cargada."); FacesContext.getCurrentInstance().addMessage(null, msg); } catch (IOException e) { e.printStackTrace(); FacesMessage error = new FacesMessage("La imagen no ha sido cargada exitosamente"); FacesContext.getCurrentInstance().addMessage(null, error); } }
From source file:com.tumblr.maximopro.iface.router.FTPHandler.java
@Override protected String getFileName(Map<String, ?> metaData) throws MXException { final MaxEndPointPropInfo fileDir = endPointPropVals.get(MicConstants.FILEDIR); // Work around: The Maximo's default implementation of // getFileName(metaData) will // automatically create a directory into local file system. In order to // avoid this, // it set the FIEDIR propvalue to the directory name that is currently // available. endPointPropVals.put(MicConstants.FILEDIR, new MaxEndPointPropInfo(MicConstants.FILEDIR, "." + File.separator, 1)); this.fileDir = fileDir.getValue(); return FilenameUtils.getName(super.getFileName(metaData)); }
From source file:de.kp.ames.web.function.upload.UploadServiceImpl.java
public void doSetRequest(RequestContext ctx) { /*/* www . j a v a 2 s .c o m*/ * The result of the upload request, returned * to the requestor; note, that the result must * be a text response */ boolean result = false; HttpServletRequest request = ctx.getRequest(); try { boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (isMultipart) { /* * Create new file upload handler */ ServletFileUpload upload = new ServletFileUpload(); /* * Parse the request */ FileItemIterator iter = upload.getItemIterator(request); while (iter.hasNext()) { FileItemStream fileItem = iter.next(); if (fileItem.isFormField()) { // not supported } else { /* * Hook into the upload request to some virus scanning * using the scanner factory of this application */ byte[] bytes = FileUtil.getByteArrayFromInputStream(fileItem.openStream()); boolean checked = MalwareScanner.scanForViruses(bytes); if (checked) { String item = this.method.getAttribute(MethodConstants.ATTR_ITEM); String type = this.method.getAttribute(MethodConstants.ATTR_TYPE); if ((item == null) || (type == null)) { this.sendNotImplemented(ctx); } else { String fileName = FilenameUtils.getName(fileItem.getName()); String mimeType = fileItem.getContentType(); try { result = upload(item, type, fileName, mimeType, bytes); } catch (Exception e) { sendBadRequest(ctx, e); } } } } } } /* * Send html response */ if (result == true) { this.sendHTMLResponse(createHtmlSuccess(), ctx.getResponse()); } else { this.sendHTMLResponse(createHtmlFailure(), ctx.getResponse()); } } catch (Exception e) { this.sendBadRequest(ctx, e); } finally { } }
From source file:com.webautomation.ScreenCaptureHtmlUnitDriver.java
String mapLocalUrl(HtmlPage page, URL link, String path, Map<String, String> replacementToAdd) throws Exception { String resultingFileName = "resources/" + FilenameUtils.getName(link.getFile()); replacementToAdd.put(path, resultingFileName); return resultingFileName; }