List of usage examples for org.apache.commons.io FilenameUtils getName
public static String getName(String filename)
From source file:hoot.services.utils.MultipartSerializer.java
private static void serializeFGDB(List<BodyPart> fileItems, String jobId, Map<String, String> uploadedFiles, Map<String, String> uploadedFilesPaths) { try {/*from w w w . java 2 s . co m*/ Map<String, String> folderMap = new HashMap<>(); for (BodyPart fileItem : fileItems) { String fileName = fileItem.getContentDisposition().getFileName(); String relPath = FilenameUtils.getPath(fileName); if (relPath.endsWith("/")) { relPath = relPath.substring(0, relPath.length() - 1); } fileName = FilenameUtils.getName(fileName); String fgdbFolderPath = HOME_FOLDER + "/upload/" + jobId + "/" + relPath; boolean isPathSafe = validatePath(HOME_FOLDER + "/upload", fgdbFolderPath); if (isPathSafe) { String pathVal = folderMap.get(fgdbFolderPath); if (pathVal == null) { File folderPath = new File(fgdbFolderPath); FileUtils.forceMkdir(folderPath); folderMap.put(fgdbFolderPath, relPath); } if (fileName == null) { throw new IOException("File name cannot be null!"); } String uploadedPath = fgdbFolderPath + "/" + fileName; boolean isFileSafe = validatePath(fgdbFolderPath, uploadedPath); if (isFileSafe) { try (InputStream fileStream = fileItem.getEntityAs(InputStream.class)) { File file = new File(uploadedPath); FileUtils.copyInputStreamToFile(fileStream, file); } } else { throw new IOException("Illegal file path:" + uploadedPath); } } else { throw new IOException("Illegal path:" + fgdbFolderPath); } } for (Map.Entry<String, String> pairs : folderMap.entrySet()) { String nameOnly = ""; String fgdbName = pairs.getValue(); String[] nParts = fgdbName.split("\\."); for (int i = 0; i < (nParts.length - 1); i++) { if (!nameOnly.isEmpty()) { nameOnly += "."; } nameOnly += nParts[i]; } uploadedFiles.put(nameOnly, "GDB"); uploadedFilesPaths.put(nameOnly, fgdbName); } } catch (Exception e) { throw new RuntimeException("Error trying to serialize FGDB!", e); } }
From source file:MSUmpire.BaseDataStructure.TandemParam.java
@Override public void SetResultFilePath(String mzXMLfile) { SpectrumPath = FilenameUtils/*from www. ja v a 2 s . c o m*/ .separatorsToUnix(FilenameUtils.getFullPath(mzXMLfile) + FilenameUtils.getName(mzXMLfile)); PepXMLPath = FilenameUtils.separatorsToUnix( FilenameUtils.getFullPath(mzXMLfile) + FilenameUtils.getBaseName(mzXMLfile) + ".tandem.pep.xml"); InteractPepXMLPath = FilenameUtils.separatorsToUnix(FilenameUtils.getFullPath(mzXMLfile) + "interact-" + FilenameUtils.getBaseName(mzXMLfile) + ".tandem.pep.xml"); ProtXMLPath = InteractPepXMLPath.replace(".pep.xml", ".prot.xml"); parameterPath = FilenameUtils.separatorsToUnix( FilenameUtils.getFullPath(mzXMLfile) + FilenameUtils.getBaseName(mzXMLfile) + ".tandem.param"); RawSearchResult = FilenameUtils.separatorsToUnix( FilenameUtils.getFullPath(mzXMLfile) + FilenameUtils.getBaseName(mzXMLfile) + ".tandem"); }
From source file:egovframework.com.utl.wed.filter.DefaultFileSaveManager.java
@Override public String saveFile(FileItem fileItem, String imageBaseDir, String imageDomain) { String originalFileName = FilenameUtils.getName(fileItem.getName()); String relUrl;//w w w . jav a2 s .com // filename String subDir = File.separator + DirectoryPathManager .getDirectoryPathByDateType(DirectoryPathManager.DIR_DATE_TYPE.DATE_POLICY_YYYY_MM); String fileName = RandomStringUtils.randomAlphanumeric(20) + "." + StringUtils.lowerCase(StringUtils.substringAfterLast(originalFileName, ".")); File newFile = new File(imageBaseDir + subDir + fileName); File fileToSave = DirectoryPathManager.getUniqueFile(newFile.getAbsoluteFile()); try { FileUtils.writeByteArrayToFile(fileToSave, fileItem.get()); } catch (IOException e) { e.printStackTrace(); } String savedFileName = FilenameUtils.getName(fileToSave.getAbsolutePath()); relUrl = StringUtils.replace(subDir, "\\", "/") + savedFileName; return imageDomain + relUrl; }
From source file:io.blobkeeper.file.domain.File.java
public File(java.io.File absolutePath) { name = FilenameUtils.getName(absolutePath.getAbsolutePath()); try {//www . j a va 2 s. c o m accessFile = new RandomAccessFile(absolutePath, "rw"); accessFile.seek(0); this.channel = accessFile.getChannel(); } catch (FileNotFoundException e) { log.error("Can't open file", e); throw new IllegalArgumentException(e); } catch (IOException e) { log.error("Can't seek file", e); throw new IllegalArgumentException(e); } }
From source file:de.sanandrew.mods.turretmod.registry.assembly.TurretAssemblyRecipes.java
private static boolean preProcessJson(Path root, final ITurretAssemblyRegistry registry) { if (Files.exists(root)) { try {//from w w w . java 2 s .c om Files.find(root, Integer.MAX_VALUE, (filePth, attr) -> FilenameUtils.getName(filePth.toString()).startsWith("group_")) .forEach(file -> processJson(file, json -> registerJsonGroup(json, registry))); } catch (IOException ex) { TmrConstants.LOG.log(Level.ERROR, String.format("Couldn't read recipe group from directory %s", root), ex); return false; } } return true; }
From source file:com.r573.enfili.common.io.file.PathBuilder.java
private void init(String initialPath) { this.separator = File.separator; this.prefix = FilenameUtils.getPrefix(initialPath); this.elements = new LinkedList<String>(); String pathWithoutPrefix = FilenameUtils.getPath(initialPath); String[] initialPathParts = pathWithoutPrefix.split("\\" + separator); for (int i = 0; i < initialPathParts.length; i++) { String thisPart = initialPathParts[i]; if ((thisPart != null) && (!thisPart.isEmpty())) { elements.add(thisPart);/*from w w w .j av a 2 s . c o m*/ } } elements.add(FilenameUtils.getName(initialPath)); }
From source file:com.enonic.cms.web.portal.instanttrace.InstantTraceResourceHandler.java
private void handleResource(HttpServletRequest request, HttpServletResponse response) throws Exception { final String fileName = FilenameUtils.getName(request.getRequestURI()); final String mimeType = mimeTypeResolver.getMimeType(fileName); final InputStream inputStream = this.resourceLoader.getResource("WEB-INF/itrace/" + fileName) .getInputStream();/* w w w . java 2 s. c o m*/ final ServletOutputStream outputStream = response.getOutputStream(); HttpServletUtil.copyNoCloseOut(inputStream, outputStream); response.setContentType(mimeType); }
From source file:com.whiuk.philip.opensmime.PathConverter.java
private static FileInformation handleFileScheme(Context context, Uri uri) { FileInputStream fileInputStream = null; final String filePath = uri.getPath(); try {/*from w w w . j av a 2s . c o m*/ File srcFile = new File(filePath); fileInputStream = new FileInputStream(srcFile); File tmpFile = copyToTempFile(context, fileInputStream); FileNameMap fileNameMap = URLConnection.getFileNameMap(); String mimeType = fileNameMap.getContentTypeFor(filePath); String fileName = FilenameUtils.getName(filePath); return new FileInformation(tmpFile, fileName, mimeType); } catch (IOException e) { Log.e(OpenSMIME.LOG_TAG, "error acquiring FileInforamtion in handleFileScheme", e); } return null; }
From source file:eu.europeana.enrichment.common.Utils.java
public static List<File> expandFileTemplateFrom(File dir, String... pattern) throws IOException { List<File> files = new ArrayList<File>(); for (String p : pattern) { File fdir = new File(new File(dir, FilenameUtils.getFullPathNoEndSeparator(p)).getCanonicalPath()); if (!fdir.isDirectory()) throw new IOException("Error: " + fdir.getCanonicalPath() + ", expanded from directory " + dir.getCanonicalPath() + " and pattern " + p + " does not denote a directory"); if (!fdir.canRead()) throw new IOException("Error: " + fdir.getCanonicalPath() + " is not readable"); FileFilter fileFilter = new WildcardFileFilter(FilenameUtils.getName(p)); File[] list = fdir.listFiles(fileFilter); if (list == null) throw new IOException("Error: " + fdir.getCanonicalPath() + " does not denote a directory or something else is wrong"); if (list.length == 0) throw new IOException("Error: no files found, template " + p + " from dir " + dir.getCanonicalPath() + " where we recognised " + fdir.getCanonicalPath() + " as path and " + fileFilter + " as file mask"); for (File file : list) { if (!file.exists()) { throw new FileNotFoundException( "File not found: " + file + " resolved to " + file.getCanonicalPath()); }//from w w w .ja v a 2s.c o m } files.addAll(Arrays.asList(list)); } return files; }
From source file:de.fau.cs.mad.smile.android.encryption.PathConverter.java
private static FileInformation handleFileScheme(Context context, Uri uri) { FileInputStream fileInputStream = null; final String filePath = uri.getPath(); try {/*from ww w .j av a 2 s . co m*/ File srcFile = new File(filePath); fileInputStream = new FileInputStream(srcFile); File tmpFile = copyToTempFile(context, fileInputStream); FileNameMap fileNameMap = URLConnection.getFileNameMap(); String mimeType = fileNameMap.getContentTypeFor(filePath); String fileName = FilenameUtils.getName(filePath); return new FileInformation(tmpFile, fileName, mimeType); } catch (IOException e) { Log.e(SMileCrypto.LOG_TAG, "error acquiring FileInforamtion in handleFileScheme", e); } return null; }