WildcardMatcher { static String[] splitBasePath(String filePattern, boolean iswindows) { if (iswindows) { filePattern = filePattern.replace("\\", "/"); } String basePath = filePattern.startsWith("/") ? "/" : ""; String[] parts = filePattern.split("/"); int firstPatternIndex = 0; for (int i = 0; i < parts.length && !containsWildcardChar(parts[i]); i++) { if (!parts[i].isEmpty()) { basePath += parts[i]; if (i < parts.length - 1) { basePath += "/"; } firstPatternIndex = i + 1; } } String patterPath = ""; for (int i = firstPatternIndex; i < parts.length ; i++) { patterPath += parts[i]; if (i < parts.length - 1) { patterPath += "/"; } } return new String[] {basePath, patterPath}; } WildcardMatcher(String wildcard);   WildcardMatcher(String wildcard, boolean windowsFs); static File[] glob(String filePattern); static void glob(String filePattern, Set<File> fileSet); boolean matches(String text);  }
@Test public void testSplitBasePath() throws Exception { assertArrayEquals(new String[]{"test.N1", ""}, WildcardMatcher.splitBasePath("test.N1", false)); assertArrayEquals(new String[]{"", "te?t.N1"}, WildcardMatcher.splitBasePath("te?t.N1", false)); assertArrayEquals(new String[]{"/home/norman/meris/data.nc", ""}, WildcardMatcher.splitBasePath("/home/norman/meris/data.nc", false)); assertArrayEquals(new String[]{"C:/Users/Norman/MERIS/data.nc", ""}, WildcardMatcher.splitBasePath("C:\\Users\\Norman\\MERIS\\data.nc", true)); assertArrayEquals(new String[]{"foo/", "*"}, WildcardMatcher.splitBasePath("footest.txt"}, WildcardMatcher.splitBasePath("footest.txt"}, WildcardMatcher.splitBasePath("/fooCVSCVS/*", false)); }