List of usage examples for org.apache.commons.io FilenameUtils normalize
public static String normalize(String filename)
From source file:com.weaforce.system.component.fckeditor.tool.UtilsFile.java
/** * Checks if a path corresponds to the rules defined <a * href="http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/Server_Side_Integration#File_Browser_Requests">here</a>. * /* w w w . j a v a2 s . c om*/ * @param path * @return <code>true</code> if path corresponds to rules or * <code>false</code>. */ public static boolean isValidPath(final String path) { if (Utils.isEmpty(path)) return false; if (!path.startsWith("/")) return false; if (!path.endsWith("/")) return false; if (!path.equals(FilenameUtils.separatorsToUnix(FilenameUtils.normalize(path)))) return false; return true; }
From source file:com.redhat.victims.VictimsScanner.java
/** * //from w ww .j a v a 2s .c o m * Iteratively finds all jar files if source is a directory and scans them * or if a file , scan it, producing {@link VictimsRecord}. This is then * written to the provided {@link VictimsOutputStream}. Embedded jars are a * record on their own. * * @param source * @param os * @throws IOException */ private static void scanSource(String source, VictimsOutputStream vos) throws IOException { File f = new File(FilenameUtils.normalize(source)); if (f.isDirectory()) { scanDir(f, vos); } else if (f.isFile()) { scanFile(f, vos); } else { throw new IOException(String.format("Invalid source file: '%s'", source)); } }
From source file:com.clank.launcher.model.modpack.FileInstall.java
private boolean shouldUpdate(UpdateCache cache, File targetFile) throws IOException { if (targetFile.exists() && isUserFile()) { return false; }//from ww w. j a v a 2 s. c o m if (!targetFile.exists()) { return true; } if (hash != null) { String existingHash = Files.hash(targetFile, hf).toString(); if (existingHash.equalsIgnoreCase(hash)) { return false; } } return cache.mark(FilenameUtils.normalize(getTargetPath()), getImpliedVersion()); }
From source file:com.ariht.maven.plugins.config.io.DirectoryReader.java
/** * Read directory creating FileInfo for each file found, include sub-directories. *///from w w w.j ava 2 s . c o m public List<FileInfo> readFiles(final String path, final List<String> filesAndDirectoriesToIgnore) throws IOException, InstantiationException, IllegalAccessException { final List<File> filesToIgnore = convertStringsToFiles(filesAndDirectoriesToIgnore); log.debug("Scanning directory: " + path); final File directory = new File(path); final Collection<File> allFiles = getAllFiles(directory, filesToIgnore); if (allFiles.isEmpty()) { log.warn("No files found in directory: " + path); } final List<FileInfo> allFilesInfo = new ArrayList<FileInfo>(allFiles.size()); final String canonicalBaseDirectory = directory.getCanonicalPath(); for (final File file : allFiles) { final FileInfo fileInfo = new FileInfo(log, file); // Remove base directory to derive sub-directory final String canonicalFilePath = FilenameUtils.getFullPathNoEndSeparator(file.getCanonicalPath()); final String subDirectory = FilenameUtils .normalize(StringUtils.replaceOnce(canonicalFilePath, canonicalBaseDirectory, "")); fileInfo.setRelativeSubDirectory(subDirectory); allFilesInfo.add(fileInfo); } return allFilesInfo; }
From source file:ch.unibas.fittingwizard.application.workflows.ExportFitWorkflow.java
public List<File> execute(WorkflowContext<ExportFitInput> input, boolean charmm_export) { logger.info("Executing export workflow with return of List<File> for CHARMM"); Fit fit = input.getParameter().getFit(); File destination = input.getParameter().getDestination(); if (destination == null) { destination = getDefaultExportDir(); logger.info("No destination passed. Using default destination: " + FilenameUtils.normalize(destination.getAbsolutePath())); }//w ww .jav a 2s . c o m List<File> exportedFiles = new ArrayList<>(); for (MoleculeId moleculeId : fit.getAllMoleculeIds()) { ExportScriptOutput output = exportScript.execute(new ExportScriptInput(fit.getId(), moleculeId)); exportedFiles.add(output.getExportFile()); } copyToDestinationIfNecessary(exportedFiles, destination); return exportedFiles; }
From source file:com.sangupta.jerry.util.FileUtils.java
/** * Returns if the given file path is an absolute file path or not. * /*from w w w . j a v a2 s.c o m*/ * @param filePath * the file path to search for * * @return <code>true</code> if the filepath is absolute, <code>false</code> * otherwise */ public static boolean isAbsolutePath(String filePath) { if (filePath == null) { throw new IllegalArgumentException("Filepath cannot be null"); } // normalize filePath = FilenameUtils.normalize(filePath); // now check String prefix = FilenameUtils.getPrefix(filePath); if (AssertUtils.isEmpty(prefix)) { return false; } return true; }
From source file:com.ariht.maven.plugins.config.ConfigGenerationMojoTest.java
/** * Given a relative path on the classpath, in this case src/tests/resources. *//* ww w .jav a 2 s .c om*/ private String getAbsolutePath(final String subDirectoryName) throws IOException { final URL resource = getClass().getResource("/"); final String normalizedAbsolutePath = FilenameUtils.normalize(resource.getFile() + subDirectoryName); final File directoryFile = new File(normalizedAbsolutePath); if (!directoryFile.exists()) { FileUtils.forceMkdir(directoryFile); } return normalizedAbsolutePath; }
From source file:edu.umn.msi.tropix.storage.core.monitor.StorageMonitorClosureImpl.java
public void apply(final File input) { if (!persistentFileMapperService.pathHasMapping(FilenameUtils.normalize(input.getAbsolutePath()))) { registerFile(input);// w w w. j ava 2s .c o m } }
From source file:com.ariht.maven.plugins.config.DirectoryReader.java
/** * Read directory creating FileInfo for each file found, include sub-directories. */// w w w .ja v a2s. co m public List<FileInfo> readFiles(final String path) throws IOException, InstantiationException, IllegalAccessException { log.debug("Scanning directory: " + path); final File directory = new File(path); final Collection<File> allFiles = getAllFiles(directory); if (allFiles.isEmpty()) { log.warn("No files found in directory: " + path); } final List<FileInfo> allFilesInfo = new ArrayList<FileInfo>(allFiles.size()); final String canonicalBaseDirectory = directory.getCanonicalPath(); for (final File file : allFiles) { final FileInfo fileInfo = new FileInfo(file); // Remove base directory to derive sub-directory final String canonicalFilePath = FilenameUtils.getFullPathNoEndSeparator(file.getCanonicalPath()); final String subDirectory = FilenameUtils.normalize( StringUtils.replaceOnce(canonicalFilePath, canonicalBaseDirectory, "") + pathSeparator); fileInfo.setRelativeSubDirectory(subDirectory); allFilesInfo.add(fileInfo); } return allFilesInfo; }
From source file:com.igormaznitsa.mindmap.model.ExtraFile.java
public boolean isSameOrHasParent(@Nonnull final File baseFolder, @Nonnull final MMapURI file) { final File theFile = this.fileUri.asFile(baseFolder); final File thatFile = file.asFile(baseFolder); final String theFilePath = FilenameUtils.normalize(theFile.getAbsolutePath()); final String thatFilePath = FilenameUtils.normalize(thatFile.getAbsolutePath()); if (theFilePath.startsWith(thatFilePath)) { final String diff = theFilePath.substring(thatFilePath.length()); return diff.isEmpty() || diff.startsWith("\\") || diff.startsWith("/") || thatFilePath.endsWith("/") || thatFilePath.endsWith("\\"); } else {//from w w w .j a v a2 s . co m return false; } }