List of usage examples for org.apache.commons.io FilenameUtils separatorsToUnix
public static String separatorsToUnix(String path)
From source file:MSUmpire.BaseDataStructure.TandemParam.java
@Override public void SetResultFilePath(String mzXMLfile) { SpectrumPath = FilenameUtils .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:com.apporiented.hermesftp.cmd.impl.FtpCmdPwd.java
/** * {@inheritDoc}//from w ww . ja va2 s .co m */ public void execute() throws FtpCmdException { String dir = FilenameUtils.separatorsToUnix(getCtx().getRemoteRelDir()); String comment = getCtx().getRes(PWD); msgOut(MSG257, new Object[] { dir, comment }); }
From source file:com.thoughtworks.go.plugin.domain.analytics.AnalyticsData.java
public String getFullViewPath() { if (StringUtils.isBlank(assetRoot)) { return viewPath; }//from w w w .ja v a 2 s. c om int positionOfQueryParamStart = viewPath.indexOf('?'); String viewPathWithoutQueryParams = positionOfQueryParamStart == -1 ? viewPath : viewPath.substring(0, positionOfQueryParamStart); String queryParams = positionOfQueryParamStart == -1 ? "" : viewPath.substring(positionOfQueryParamStart); return URI .create(FilenameUtils.separatorsToUnix(Paths.get(assetRoot, viewPathWithoutQueryParams).toString()) + queryParams) .normalize().toString(); }
From source file:net.shopxx.util.CompressUtils.java
public static void archive(File[] srcFiles, File destFile, String archiverName) { Assert.notNull(destFile);//from w ww. j a v a 2 s.c o m Assert.state(!destFile.exists() || destFile.isFile()); Assert.hasText(archiverName); File parentFile = destFile.getParentFile(); if (parentFile != null) { parentFile.mkdirs(); } ArchiveOutputStream archiveOutputStream = null; try { archiveOutputStream = new ArchiveStreamFactory().createArchiveOutputStream(archiverName, new BufferedOutputStream(new FileOutputStream(destFile))); if (ArrayUtils.isNotEmpty(srcFiles)) { for (File srcFile : srcFiles) { if (srcFile == null || !srcFile.exists()) { continue; } Set<File> files = new HashSet<File>(); if (srcFile.isFile()) { files.add(srcFile); } if (srcFile.isDirectory()) { files.addAll(FileUtils.listFilesAndDirs(srcFile, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)); } String basePath = FilenameUtils.getFullPath(srcFile.getCanonicalPath()); for (File file : files) { try { String entryName = FilenameUtils.separatorsToUnix( StringUtils.substring(file.getCanonicalPath(), basePath.length())); ArchiveEntry archiveEntry = archiveOutputStream.createArchiveEntry(file, entryName); archiveOutputStream.putArchiveEntry(archiveEntry); if (file.isFile()) { InputStream inputStream = null; try { inputStream = new BufferedInputStream(new FileInputStream(file)); IOUtils.copy(inputStream, archiveOutputStream); } catch (FileNotFoundException e) { throw new RuntimeException(e.getMessage(), e); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } finally { IOUtils.closeQuietly(inputStream); } } } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } finally { archiveOutputStream.closeArchiveEntry(); } } } } } catch (ArchiveException e) { throw new RuntimeException(e.getMessage(), e); } catch (FileNotFoundException e) { throw new RuntimeException(e.getMessage(), e); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } finally { IOUtils.closeQuietly(archiveOutputStream); } }
From source file:com.igormaznitsa.nbmindmap.nb.refactoring.elements.RenameFileActionPlugin.java
protected static String replaceNameInPath(int pathItemIndexFromEnd, final String path, final String newName) { int foldersInNewName = numberOfFolders(newName); final String normalizedSeparators = FilenameUtils.separatorsToUnix(path); int start = normalizedSeparators.length(); while (start >= 0 && pathItemIndexFromEnd >= 0) { start = normalizedSeparators.lastIndexOf('/', start - 1); pathItemIndexFromEnd--;/*from ww w. j a va 2 s. co m*/ } String result = path; if (start >= 0) { final int indexEnd = normalizedSeparators.indexOf('/', start + 1); while (start >= 0 && foldersInNewName > 0) { start = normalizedSeparators.lastIndexOf('/', start - 1); foldersInNewName--; } if (start >= 0) { if (indexEnd <= 0) { result = path.substring(0, start + 1) + newName; } else { result = path.substring(0, start + 1) + newName + path.substring(indexEnd); } } } return result; }
From source file:gov.nih.nci.cbiit.cmts.util.ResourceUtils.java
/** * Get the relative path from one file to another, specifying the directory separator. * If one of the provided resources does not exist, it is assumed to be a file unless it ends with '/' or * '\'.//from w w w . j a v a 2 s.co m * * @param targetPath is calculated to this file * @param basePath is calculated from this file * @param pathSeparator directory separator. The platform default is not assumed so that we can test Unix behaviour when running on Windows (for example) * @return target relative path from the base */ public static String getRelativePath(String targetPath, String basePath, String pathSeparator) { if (targetPath.toLowerCase().startsWith("file:/")) { targetPath = targetPath.substring(6); while (targetPath.startsWith("/")) targetPath = targetPath.substring(1); } if (basePath.toLowerCase().startsWith("file:/")) { basePath = basePath.substring(6); while (basePath.startsWith("/")) basePath = basePath.substring(1); } String tempS = basePath; while (true) { File baseF = new File(tempS); if ((baseF.exists()) && (baseF.isFile())) { basePath = baseF.getAbsolutePath(); break; } if (!pathSeparator.equals("/")) break; if (tempS.startsWith("/")) break; tempS = "/" + tempS; } tempS = targetPath; while (true) { File targetF = new File(tempS); if ((targetF.exists()) && (targetF.isFile())) { targetPath = targetF.getAbsolutePath(); break; } if (!pathSeparator.equals("/")) break; if (tempS.startsWith("/")) break; tempS = "/" + tempS; } // Normalize the paths //System.out.println("ResourceUtils.getRelativePath()..target("+pathSeparator+"):"+targetPath); //System.out.println("ResourceUtils.getRelativePath()..base("+pathSeparator+"):"+basePath); String normalizedTargetPath = FilenameUtils.normalizeNoEndSeparator(targetPath); String normalizedBasePath = FilenameUtils.normalizeNoEndSeparator(basePath); // Undo the changes to the separators made by normalization if (pathSeparator.equals("/")) { normalizedTargetPath = FilenameUtils.separatorsToUnix(normalizedTargetPath); normalizedBasePath = FilenameUtils.separatorsToUnix(normalizedBasePath); } else if (pathSeparator.equals("\\")) { normalizedTargetPath = FilenameUtils.separatorsToWindows(normalizedTargetPath); normalizedBasePath = FilenameUtils.separatorsToWindows(normalizedBasePath); } else { throw new IllegalArgumentException("Unrecognised dir separator '" + pathSeparator + "'"); } //System.out.println("ResourceUtils.getRelativePath()..normalizedTarget("+pathSeparator+"):"+normalizedTargetPath); //System.out.println("ResourceUtils.getRelativePath()..normalizedBase("+pathSeparator+"):"+normalizedBasePath); String[] base = normalizedBasePath.split(Pattern.quote(pathSeparator)); String[] target = normalizedTargetPath.split(Pattern.quote(pathSeparator)); // First get all the common elements. Store them as a string, // and also count how many of them there are. StringBuffer common = new StringBuffer(); int commonIndex = 0; while (commonIndex < target.length && commonIndex < base.length && target[commonIndex].trim().equals(base[commonIndex].trim())) { common.append(target[commonIndex].trim() + pathSeparator); commonIndex++; } if (commonIndex == 0) { // No single common path element. This most // likely indicates differing drive letters, like C: and D:. // These paths cannot be relativized. File ff = new File(targetPath); if ((ff.exists()) && (ff.isFile())) return ff.getAbsolutePath(); else throw new IllegalArgumentException("No common path element found for '" + normalizedTargetPath + "' and '" + normalizedBasePath + "'"); } // The number of directories we have to backtrack depends on whether the base is a file or a dir // For example, the relative path from // // /foo/bar/baz/gg/ff to /foo/bar/baz // // ".." if ff is a file // "../.." if ff is a directory // // The following is a heuristic to figure out if the base refers to a file or dir. It's not perfect, because // the resource referred to by this path may not actually exist, but it's the best I can do boolean baseIsFile = true; File baseResource = new File(normalizedBasePath); if (baseResource.exists()) { baseIsFile = baseResource.isFile(); } else if (basePath.endsWith(pathSeparator)) { baseIsFile = false; } StringBuffer relative = new StringBuffer(); if (base.length != commonIndex) { int numDirsUp = baseIsFile ? base.length - commonIndex - 1 : base.length - commonIndex; for (int i = 0; i < numDirsUp; i++) { relative.append(".." + pathSeparator); } } relative.append(normalizedTargetPath.substring(common.length())); //System.out.println("ResourceUtils.getRelativePath()..relativeTarget:"+relative.toString()); return relative.toString(); }
From source file:com.clank.launcher.builder.ClientFileCollector.java
@Override protected void onFile(File file, String relPath) throws IOException { if (file.getName().endsWith(FileInfoScanner.FILE_SUFFIX)) { return;//from w w w . j a va 2s .co m } FileInstall entry = new FileInstall(); String hash = Files.hash(file, hf).toString(); String hashedPath = hash.substring(0, 2) + "/" + hash.substring(2, 4) + "/" + hash; File destPath = new File(destDir, hashedPath); entry.setHash(hash); entry.setLocation(hashedPath); entry.setTo(FilenameUtils.separatorsToUnix(FilenameUtils.normalize(relPath))); entry.setSize(file.length()); applicator.apply(entry); destPath.getParentFile().mkdirs(); ClientFileCollector.log.info(String.format("Adding %s from %s...", relPath, file.getAbsolutePath())); Files.copy(file, destPath); manifest.getTasks().add(entry); }
From source file:de.fu_berlin.inf.dpp.intellij.project.fs.PathImp.java
public PathImp(final String path) { this.path = path; String splitPath = path;/* ww w. java2s . c o m*/ //We must remove the first slash, otherwise String.split would //create an empty string as first segment if (path.startsWith("\\") || path.startsWith("/")) { splitPath = path.substring(1); } //"foo\bla.txt" is a valid linux path, which would not be handled // correctly by the separatorsToUnix. However, IntelliJ does not handle // these paths correctly and the FS Synchronizer logs an error when // encountering one. Thus it is not possible that PathImp is called with // such a path and we can safely use this method. splitPath = FilenameUtils.separatorsToUnix(splitPath); segments = splitPath.split(Pattern.quote(FILE_SEPARATOR)); }
From source file:com.consol.citrus.admin.controller.ProjectController.java
@RequestMapping(method = RequestMethod.POST) @ResponseBody/*from w w w . jav a2 s . co m*/ public ModelAndView browseProjectHome(@RequestParam("dir") String dir) { String directory = FilenameUtils .separatorsToSystem(fileHelper.decodeDirectoryUrl(dir, configurationService.getRootDirectory())); String[] folders = fileHelper.getFolders(new File(directory)); ModelAndView view = new ModelAndView("FileTree"); view.addObject("folders", folders); view.addObject("baseDir", FilenameUtils.separatorsToUnix(directory)); return view; }
From source file:com.thoughtworks.go.config.ArtifactConfig.java
public String getDestination() { return StringUtils.isBlank(destination) ? DEFAULT_ROOT.getPath() : FilenameUtils.separatorsToUnix(destination); }