FilenameUtils { public static int getPrefixLength(String filename) { if (filename == null) { return -1; } int len = filename.length(); if (len == 0) { return 0; } char ch0 = filename.charAt(0); if (ch0 == ':') { return -1; } if (len == 1) { if (ch0 == '~') { return 2; } return (isSeparator(ch0) ? 1 : 0); } else { if (ch0 == '~') { int posUnix = filename.indexOf(UNIX_SEPARATOR, 1); int posWin = filename.indexOf(WINDOWS_SEPARATOR, 1); if (posUnix == -1 && posWin == -1) { return len + 1; } posUnix = (posUnix == -1 ? posWin : posUnix); posWin = (posWin == -1 ? posUnix : posWin); return Math.min(posUnix, posWin) + 1; } char ch1 = filename.charAt(1); if (ch1 == ':') { ch0 = Character.toUpperCase(ch0); if (ch0 >= 'A' && ch0 <= 'Z') { if (len == 2 || isSeparator(filename.charAt(2)) == false) { return 2; } return 3; } return -1; } else if (isSeparator(ch0) && isSeparator(ch1)) { int posUnix = filename.indexOf(UNIX_SEPARATOR, 2); int posWin = filename.indexOf(WINDOWS_SEPARATOR, 2); if ((posUnix == -1 && posWin == -1) || posUnix == 2 || posWin == 2) { return -1; } posUnix = (posUnix == -1 ? posWin : posUnix); posWin = (posWin == -1 ? posUnix : posWin); return Math.min(posUnix, posWin) + 1; } else { return (isSeparator(ch0) ? 1 : 0); } } } FilenameUtils(); static String normalize(String filename); static String normalize(String filename, boolean unixSeparator); static String normalizeNoEndSeparator(String filename); static String normalizeNoEndSeparator(String filename, boolean unixSeparator); static String concat(String basePath, String fullFilenameToAdd); static String separatorsToUnix(String path); static String separatorsToWindows(String path); static String separatorsToSystem(String path); static int getPrefixLength(String filename); static int indexOfLastSeparator(String filename); static int indexOfExtension(String filename); static String getPrefix(String filename); static String getPath(String filename); static String getPathNoEndSeparator(String filename); static String getFullPath(String filename); static String getFullPathNoEndSeparator(String filename); static String getName(String filename); static String getBaseName(String filename); static String getExtension(String filename); static String removeExtension(String filename); static boolean equals(String filename1, String filename2); static boolean equalsOnSystem(String filename1, String filename2); static boolean equalsNormalized(String filename1, String filename2); static boolean equalsNormalizedOnSystem(String filename1, String filename2); static boolean equals(
            String filename1, String filename2,
            boolean normalized, IOCase caseSensitivity); static boolean isExtension(String filename, String extension); static boolean isExtension(String filename, String[] extensions); static boolean isExtension(String filename, Collection<String> extensions); static boolean wildcardMatch(String filename, String wildcardMatcher); static boolean wildcardMatchOnSystem(String filename, String wildcardMatcher); static boolean wildcardMatch(String filename, String wildcardMatcher, IOCase caseSensitivity); static final char EXTENSION_SEPARATOR; static final String EXTENSION_SEPARATOR_STR; }
@Test public void testGetPrefixLength() throws Exception { assertEquals(0, FilenameUtils.getPrefixLength("src/test/java/nl/nn/adapterframework/util/t.txt")); assertEquals(7, FilenameUtils.getPrefixLength("~userz/a/b/c.txt")); }