ImageBatchCompressor { protected List<File> findMatchFiles() { String dir = FileUtils.convertDir(baseDir); File dirFile = new File(dir); return FileUtils.list(dirFile, file -> { String fullpath = FileUtils.replaceBackSlashToSlash(file.getPath()); String subpath = StringUtils.substringAfter(fullpath, dir); return Stream.of(antPatterns).anyMatch(pattern -> antMatcher.match(pattern, subpath)); }, true); }  void initialize(); List<String> compress(); void setBaseDir(String baseDir); void setAntPattern(String...antPatterns);  }
@Test public void testFindMatchFiles() { ImageBatchCompressor compressor = new ImageBatchCompressor(); compressor.setBaseDir("文件夹"); compressor.setAntPattern("*.png"); compressor.initialize(); compressor.findMatchFiles().forEach(file -> { System.out.println("file: " + file); }); }