List of usage examples for org.apache.commons.io FilenameUtils separatorsToUnix
public static String separatorsToUnix(String path)
From source file:com.xiaomi.linden.client.LindenClient.java
private LindenService.ServiceIface buildClient(String parent, String node) { String nodePath = FilenameUtils.separatorsToUnix(FilenameUtils.concat(parent, node)); byte[] bytes = zkClient.readData(nodePath); ServiceInstance serviceInstance = JSONObject.parseObject(new String(bytes), ServiceInstance.class); String schema = String.format("%s:%s", serviceInstance.getServiceEndpoint().getHost(), serviceInstance.getServiceEndpoint().getPort()); return Thrift.newIface(schema, LindenService.ServiceIface.class); }
From source file:com.wlami.mibox.client.application.PropertyAppSettings.java
@Override public void setWatchDirectory(final String watchDirectory) { this.watchDirectory = FilenameUtils.separatorsToUnix(watchDirectory); }
From source file:com.mgmtp.jfunk.common.util.ResourceLoader.java
/** * Loads a resource as {@link InputStream}. * //from ww w.j a va 2 s . c om * @param resource * The resource to be loaded. If {@code baseDir} is not {@code null}, it is loaded * relative to {@code baseDir}. * @return The stream */ public static InputStream getInputStream(final File resource) throws IOException { if (resource.exists()) { return new FileInputStream(resource); } LOG.info("Could not find file '" + resource.getAbsolutePath() + "' in the file system. Trying to load it from the classpath..."); String path = FilenameUtils.separatorsToUnix(resource.getPath()); ClassLoader cl = Thread.currentThread().getContextClassLoader(); InputStream is = cl.getResourceAsStream(path); if (is == null) { if (path.startsWith("/")) { LOG.info("Could not find file '" + resource + " in the file system. Trying to load it from the classpath without the leading slash..."); is = cl.getResourceAsStream(path.substring(1)); } if (is == null) { // If configs are to be loaded from the classpath, we also try it directly // stripping of the config directory String configDir = new File(getConfigDir()).getName(); if (path.startsWith(configDir)) { is = cl.getResourceAsStream(StringUtils.substringAfter(path, configDir + '/')); } } if (is == null) { throw new FileNotFoundException("Could not load file '" + resource + "'"); } } return is; }
From source file:com.ariht.maven.plugins.config.ConfigProcessorMojo.java
/** * Filter files contain the properties we wish to substitute in templates. * * Uses Apache Commons Configuration to load filters. *//*from ww w .ja v a 2s .c o m*/ private Properties readFilterIntoProperties(final FileInfo filter) throws ConfigurationException { final PropertiesConfiguration config = new PropertiesConfiguration(filter.getFile()); config.setEncoding(encoding); // Add one more property: filter.source=/relative/sub/dir/filenameNoExtension final String filterSource = filter.getRelativeSubDirectory() + filter.getNameWithoutExtension(); config.setProperty("filter.source", FilenameUtils.separatorsToUnix(filterSource)); return ConfigurationConverter.getProperties(config); }
From source file:jenkins.plugins.publish_over.BPBuildInfo.java
private String removePrefix(final String relativePathToFile, final String expandedPrefix) { if (expandedPrefix == null) return relativePathToFile; String toRemove = Util .fixEmptyAndTrim(FilenameUtils.separatorsToUnix(FilenameUtils.normalize(expandedPrefix + "/"))); if (toRemove != null) { if (toRemove.charAt(0) == '/') toRemove = toRemove.substring(1); if (!relativePathToFile.startsWith(toRemove)) { throw new BapPublisherException( Messages.exception_removePrefix_noMatch(relativePathToFile, toRemove)); }//from ww w.ja v a 2 s . c om return relativePathToFile.substring(toRemove.length()); } return relativePathToFile; }
From source file:com.thoughtworks.go.domain.ArtifactPlan.java
public List<File> uploadTestResults(GoPublisher publisher, File rootPath) { List<File> allFiles = new ArrayList<>(); for (ArtifactPlan artifactPlan : testArtifactPlansForMerging) { File[] files = getArtifactFiles(rootPath, artifactPlan); if (files.length > 0) { allFiles.addAll(uploadArtifactFile(publisher, rootPath, artifactPlan.getSrc(), artifactPlan.getDest(), files)); } else {/*from w w w. j a va 2 s . c o m*/ final String message = MessageFormat.format( "The Directory {0} specified as a test artifact was not found." + " Please check your configuration", FilenameUtils.separatorsToUnix(artifactPlan.getSource(rootPath).getPath())); publisher.taggedConsumeLineWithPrefix(GoPublisher.PUBLISH_ERR, message); LOG.error(message); } } return allFiles; }
From source file:com.thoughtworks.go.server.presentation.models.JobDetailPresentationModel.java
public String getRestfulUrl(String path) { return BASE_FILE_URL + jobIdentifier.buildLocator() + "/" + FilenameUtils.separatorsToUnix(path); }
From source file:de.hybris.platform.impex.jalo.ImpExMediasImportTest.java
/** * Calls the <code>importData</code> method of given handler with an absolute file path in different formats. Tests * path formats in windows and unix notation as well as in relative and absolute. * /* w w w .j av a 2 s . c o m*/ * @param handler * handler which will be used for test * @param media * media where the data will be imported to */ private void mediaImportFromAbsolute(final MediaDataHandler handler, final Media media) { File testFile = null; try { testFile = File.createTempFile("mediaImportTest", ".txt"); final PrintWriter printer = new PrintWriter(testFile); printer.print("testest"); printer.close(); } catch (final IOException e) { e.printStackTrace(); fail(e.getMessage()); } final String unixPathRel = ImpExConstants.Syntax.ABSOLUTE_FILE_PATH_PREFIX + FilenameUtils.separatorsToUnix(testFile.getPath()); final String unixPathAbs = ImpExConstants.Syntax.ABSOLUTE_FILE_PATH_PREFIX + FilenameUtils.separatorsToUnix(testFile.getAbsolutePath()); final String winPathRel = ImpExConstants.Syntax.ABSOLUTE_FILE_PATH_PREFIX + FilenameUtils.separatorsToWindows(testFile.getPath()); final String winPathAbs = ImpExConstants.Syntax.ABSOLUTE_FILE_PATH_PREFIX + FilenameUtils.separatorsToWindows(testFile.getAbsolutePath()); mediaImport(handler, media, unixPathRel, "testest"); mediaImport(handler, media, unixPathAbs, "testest"); mediaImport(handler, media, winPathRel, "testest"); mediaImport(handler, media, winPathAbs, "testest"); if (!testFile.delete()) { fail("Can not delete temp file: " + testFile.getPath()); } }
From source file:com.thoughtworks.go.publishers.GoArtifactsManipulator.java
private Properties computeChecksumForContentsOfDirectory(File directory, String destPath) throws IOException { Collection<File> fileStructure = FileUtils.listFiles(directory, null, true); Properties checksumProperties = new Properties(); for (File file : fileStructure) { String filePath = removeStart(file.getAbsolutePath(), directory.getParentFile().getAbsolutePath()); try (FileInputStream inputStream = new FileInputStream(file)) { checksumProperties.setProperty( getEffectiveFileName(destPath, FilenameUtils.separatorsToUnix(filePath)), md5Hex(inputStream)); }//www . ja v a2s .co m } return checksumProperties; }
From source file:fr.fastconnect.factory.tibco.bw.maven.source.AbstractProjectsListMojo.java
/** * <p>/*from w ww. j av a 2s . c o m*/ * 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 '\'. * </p> * * @param targetPath targetPath is calculated to this file * @param basePath 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 */ public static String getRelativePath(String targetPath, String basePath, String pathSeparator) { // Normalize the paths 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 + "'"); } 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].equals(base[commonIndex])) { common.append(target[commonIndex] + 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. throw new PathResolutionException("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())); return relative.toString(); }