FileUtil { public static String globToRegex(String glob) { glob = glob.replaceAll("\\^", "\\\\\\^"); glob = glob.replaceAll("\\$", "\\\\\\$"); glob = glob.replaceAll("\\.", "\\\\."); glob = glob.replaceAll("\\\\", "\\\\"); glob = glob.replaceAll("\\*", ".*"); glob = glob.replaceAll("\\?", "."); return "^" + glob + "$"; }  static PrintWriter openForWriting(File file); static PrintWriter openForWriting(File file, Charset encoding); static BufferedReader openForReading(File file); static BufferedReader openForReading(File file, Charset encoding); static List<String> readLines(File inputFile); static List<String> readLines(File inputFile, Charset encoding); static void processTree(File root, FileTask task); static void processTree(File dir, String glob, boolean recurseSubdirs, FileTask task); static File findFile(List<File> dirsToSearch, String pathToFile, List<String> extensions); static File addNumberToExistingFileName(File file); static File[] listFilesSorted(File dir); static String globToRegex(String glob); final static Comparator<File> LIST_FILES_COMPARATOR; }
@Test public void testGlobToRegex() { Assert.assertEquals("^.*\\.txt$", FileUtil.globToRegex("*.txt")); Assert.assertEquals("^bla..\\.csv$", FileUtil.globToRegex("bla??.csv")); Assert.assertEquals("^b\\$\\^\\.txt$", FileUtil.globToRegex("b$^.txt")); }