List of usage examples for org.apache.commons.io FilenameUtils normalizeNoEndSeparator
public static String normalizeNoEndSeparator(String filename, boolean unixSeparator)
From source file:it.anyplace.sync.core.utils.PathUtils.java
public static String normalizePath(String path) { return FilenameUtils.normalizeNoEndSeparator(path, true).replaceFirst("^" + PATH_SEPARATOR, ""); }
From source file:jp.furplag.util.commons.FileUtils.java
private static String normalize(String filename) { return FilenameUtils.normalizeNoEndSeparator(filename, true); }
From source file:com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder.java
public String extractFinalPieceFromPath(final String path) { if (path == null || path.length() == 0) { return ""; }//from w ww. j av a 2 s . c o m final String normalizedPath = FilenameUtils.normalizeNoEndSeparator(path, true); return normalizedPath.substring(normalizedPath.lastIndexOf("/") + 1, normalizedPath.length()); }
From source file:com.centeractive.ws.builder.utils.ResourceUtils.java
private static String constructResourcePath(String packagePath, String resourceName) { String resourcePath = String.format("/%s/%s", packagePath, resourceName); String resourcePathUnixSeparators = FilenameUtils.separatorsToUnix(resourcePath); String resourcePathNoLeadingSeparators = removeLeadingUnixSeparators(resourcePathUnixSeparators); String normalizedResourcePath = FilenameUtils.normalizeNoEndSeparator(resourcePathNoLeadingSeparators, true);/*w w w . j a v a2s . c o m*/ return normalizedResourcePath; }
From source file:com.themodernway.server.core.file.FileUtils.java
public static final String normalize(String path) { path = StringOps.toTrimOrNull(path); if (null != path) { path = StringOps.toTrimOrNull(FilenameUtils.normalizeNoEndSeparator(patch(path), true)); if ((null != path) && (CommonOps.IS_NOT_FOUND != path.indexOf(SINGLE_PREFIX_CHAR))) { if (path.startsWith(TILDE_SLASHY)) { return normalize(path.substring(2)); }/*w w w .j a va 2 s .com*/ if (path.startsWith(SLASHY_TILDE)) { return normalize(SINGLE_SLASH + path.substring(2)); } if (path.startsWith(SINGLE_TILDE)) { return normalize(path.substring(1)); } } } return path; }
From source file:net.certiv.antlr.project.regen.ReGenConfig.java
public String packageOf(String parent, String modelRoot) { String pkg = FilenameUtils.normalizeNoEndSeparator(parent, true); String bse = FilenameUtils.normalizeNoEndSeparator(modelRoot, true); int dot = bse.length() + 1; if (dot >= pkg.length()) return ""; pkg = pkg.substring(dot);/* www . j av a 2 s. c om*/ pkg = pkg.replace('/', '.'); return pkg; }
From source file:com.flexdms.htmltemplate.HtmlTemplateMojo.java
protected void transformFile(String fileName, File base, Writer writer, String template, List<String> modules) throws FileNotFoundException, IOException { String name = FilenameUtils.normalizeNoEndSeparator(fileName, true); getLog().info("process " + name); List<String> lines = IOUtils.readLines(new FileReader(new File(base, fileName))); StringBuilder sb = new StringBuilder(); if (process) { sb.append("\"\""); }/*ww w.j a va 2 s . co m*/ for (String line : lines) { if (process) { String newline = "+\"" + line.replace("\"", "\\\"") + "\"\n"; sb.append(newline); } else { sb.append(line); sb.append("\n"); } } String r1 = template.replace("@@@@name@@@@", name); String r2 = r1.replace("@@@@text@@@@", sb.toString()); modules.add(name); writer.write("\n\n" + r2); }
From source file:org.grycap.gpf4med.URLUtilsTest.java
@Test public void test() { System.out.println("URLUtilsTest.test()"); try {//from ww w . java2s . c o m // load index final String[] validLines = new String[] { "file:///path/to/local-file-system", "http://www.google.com/index.html", "https://github.com/index.html # GitHub" }; final String[] invalidLines = new String[] { "/path/to/local-file-system", "invalid_protocol://www.google.com/index.html" }; final String[] commentLines = new String[] { "#file:///path/to/local-file-system", " # http://www.google.com/index.html", "#file:///path/to/local-file-system", " # http://www.google.com/index.html", " #file:///path/to/local-file-system" }; final List<String> linesList = new ArrayList<String>(); linesList.addAll(Arrays.asList(validLines)); linesList.addAll(Arrays.asList(invalidLines)); linesList.addAll(Arrays.asList(commentLines)); final String indexFilename = FilenameUtils.concat(TEST_OUTPUT_DIR, "index.txt"); FileUtils.writeLines(new File(indexFilename), linesList); final URL[] urls = URLUtils.readIndex(new File(indexFilename).toURI().toURL()); assertThat("URLs is not null", urls, notNullValue()); assertThat("number of readed URLs coincides", urls.length, equalTo(validLines.length)); for (final String line : validLines) { boolean found = false; final String target = new StringTokenizer(line).nextToken(); for (int i = 0; i < urls.length && !found; i++) { final String query = (!URLUtils.isFileProtocol(urls[i]) ? urls[i].toString() : URLUtils.FILE + "://" + urls[i].getPath()); if (query.equals(target)) { found = true; } } assertThat("a valid URL was found in the index: " + line, found); } // parse URL final String[][] paths = { { "file:///foo", "/foo" }, { "/foo//", "/foo/" }, { "/foo/./", "/foo/" }, { "/foo/../bar", "/bar" }, { "/foo/../bar/", "/bar/" }, { "/foo/../bar/../baz", "/baz" }, { "//foo//./bar", "/foo/bar" }, { "/../", null }, { "../foo", FilenameUtils.concat(System.getProperty("user.dir"), "../foo") }, { "foo/bar/..", FilenameUtils.concat(System.getProperty("user.dir"), "foo/bar/..") }, { "foo/../../bar", FilenameUtils.concat(System.getProperty("user.dir"), "foo/../../bar") }, { "foo/../bar", FilenameUtils.concat(System.getProperty("user.dir"), "foo/../bar") }, { "//server/foo/../bar", "/server/bar" }, { "//server/../bar", null }, { "C:\\foo\\..\\bar", "/bar" }, { "C:\\..\\bar", null }, { "~/foo/../bar/", FilenameUtils.concat(System.getProperty("user.home"), "foo/../bar/") }, { "~/../bar", FilenameUtils.concat(System.getProperty("user.home"), "../bar") }, { "http://localhost", null } }; for (int i = 0; i < paths.length; i++) { URL url = null; try { url = URLUtils.parseURL(paths[i][0]); System.out.println("PATH='" + paths[i][0] + "', URL='" + (url != null ? url.toString() : "NULL") + "', EXPECTED='" + paths[i][1] + "'"); assertThat("URL is not null", url, notNullValue()); if (URLUtils.isFileProtocol(url)) { final File file = FileUtils.toFile(url); assertThat("file is not null", file, notNullValue()); assertThat("file name coincides", FilenameUtils.normalizeNoEndSeparator(file.getCanonicalPath(), true) .equals(FilenameUtils.normalizeNoEndSeparator(paths[i][1], true))); } } catch (IOException ioe) { if (paths[i][1] != null) { throw ioe; } else { System.out.println("PATH='" + paths[i][0] + "' thrown the expected exception"); } } } // validate URL assertThat("valid URL", URLUtils.isValid("http://www.google.com", true)); assertThat("valid URL", !URLUtils.isValid("http://invalidURL^$&%$&^", true)); assertThat("valid URL", URLUtils.isValid("http://example.com/file[/].html", false)); assertThat("valid URL", !URLUtils.isValid("http://example.com/file[/].html", true)); } catch (Exception e) { e.printStackTrace(System.err); fail("URLUtilsTest.test() failed: " + e.getMessage()); } finally { System.out.println("URLUtilsTest.test() has finished"); } }
From source file:org.jodconverter.office.LocalOfficeUtilsTest.java
/** Tests the LocalOfficeUtils.toUrl function on Windows OS. */ @Test/* w w w . jav a 2s . c o m*/ public void windowsToUrl() { assumeTrue(SystemUtils.IS_OS_WINDOWS); String tempDir = System.getProperty("java.io.tmpdir"); final File tempDirFile = new File(tempDir); tempDir = FilenameUtils.normalizeNoEndSeparator(tempDir, true); assertThat(toUrl(new File(tempDirFile, "document.odt"))).isEqualTo("file:///" + tempDir + "/document.odt"); assertThat(toUrl(new File(tempDirFile, "document with spaces.odt"))) .isEqualTo("file:///" + tempDir + "/document%20with%20spaces.odt"); }
From source file:org.ngrinder.common.util.PathUtils.java
/** * Join two path without appending '/'.//from ww w . j a v a 2 s . c om * * @param path1 path1 * @param path2 path2 * @return joined path */ public static String join(String path1, String path2) { path1 = trimPathSeparatorBothSides(path1); path2 = trimPathSeparatorBothSides(path2); return FilenameUtils.normalizeNoEndSeparator(path1 + "/" + path2, true); }