/** * Performs scanning. */ @SuppressWarnings("StatementWithEmptyBody") public void find() { while (nextFile() != null) { } }
public boolean hasNext() { nextFile = nextFile(); return nextFile != null; }
@Override public boolean hasNext() { nextFile = nextFile(); return nextFile != null; }
/** * Finds all files and returns list of founded files. */ public List<File> findAll() { List<File> allFiles = new ArrayList<>(); File file; while ((file = nextFile()) != null) { allFiles.add(file); } return allFiles; }
/** * Finds a file. */ public void find(FileConsumer fileConsumer) { File f; while ((f = nextFile()) != null) { boolean next = fileConsumer.onFile(f); if (!next) { break; } } }
/** * Clears all settings and removes all created bundle files from file system. */ public synchronized void reset() { if (strategy == Strategy.ACTION_MANAGED) { actionBundles.clear(); mirrors.clear(); } FindFile ff = new FindFile(); ff.includeDirs(false); ff.searchPath(new File(bundleFolder, staplerPath)); File f; int count = 0; while ((f = ff.nextFile()) != null) { f.delete(); count++; } if (log.isInfoEnabled()) { log.info("reset: " + count + " bundle files deleted."); } }
/** * Scans single classpath directory. * @see #onEntry(EntryData) */ protected void scanClassPath(File root) { String rootPath = root.getAbsolutePath(); if (!rootPath.endsWith(File.separator)) { rootPath += File.separatorChar; } FindFile ff = new FindFile().setIncludeDirs(false).setRecursive(true).searchPath(rootPath); File file; while ((file = ff.nextFile()) != null) { String filePath = file.getAbsolutePath(); try { if (StringUtil.endsWithIgnoreCase(filePath, CLASS_FILE_EXT)) { scanClassFile(filePath, rootPath, file, true); } else if (includeResources) { scanClassFile(filePath, rootPath, file, false); } } catch (RuntimeException rex) { if (!ignoreException) { throw rex; } } } }
/** * Scans single classpath directory. * @see #onEntry(ClassPathEntry) */ protected void scanClassPath(final File root) { String rootPath = root.getAbsolutePath(); if (!rootPath.endsWith(File.separator)) { rootPath += File.separatorChar; } final FindFile ff = FindFile.create().includeDirs(false).recursive(true).searchPath(rootPath); File file; while ((file = ff.nextFile()) != null) { final String filePath = file.getAbsolutePath(); try { if (StringUtil.endsWithIgnoreCase(filePath, CLASS_FILE_EXT)) { scanClassFile(filePath, rootPath, file, true); } else if (includeResources) { scanClassFile(filePath, rootPath, file, false); } } catch (RuntimeException rex) { if (!ignoreException) { throw rex; } } } }
@Test void testJustFoldersAndFiles() { FindFile ff = new FindFile(); ff.includeDirs(false); ff.includeFiles(true); ff.recursive(false); ff.sortByName(); ff.searchPath(dataRoot); File f; StringBuilder str = new StringBuilder(); while ((f = ff.nextFile()) != null) { str.append(f.getName()).append(" | "); } assertEquals("alpha.txt | jodd1.txt | jodd10.txt | zero.txt | ", str.toString()); ff = new FindFile(); ff.includeDirs(true); ff.includeFiles(false); ff.recursive(false); ff.sortByName(); ff.searchPath(dataRoot); str = new StringBuilder(); while ((f = ff.nextFile()) != null) { str.append(f.getName()).append(" | "); } assertEquals("beta | sumo | ", str.toString()); }
/** * 13s */ @Test void testLiveHtmls() throws IOException { FindFile ff = new WildcardFindFile().include("**/*.html"); ff.searchPath(testLiveRoot); File file; boolean processed = false; while ((file = ff.nextFile()) != null) { processed = true; String name = file.getName(); System.out.println('+' + name); String content = FileUtil.readString(file); try { _parseEmpty(content); } catch (Exception ex) { ex.printStackTrace(); fail(ex.toString()); } } assertTrue(processed); }
while ((f = ff.nextFile()) != null) { str.append(f.getName()).append(" | "); str.setLength(0); while ((f = ff.nextFile()) != null) { str.append(f.getName()).append(" | "); str.setLength(0); while ((f = ff.nextFile()) != null) { str.append(f.getName()).append(" | "); str.setLength(0); while ((f = ff.nextFile()) != null) { str.append(f.getName()).append(" | "); str.setLength(0); while ((f = ff.nextFile()) != null) { str.append(f.getName()).append(" | ");
@Test void testWildcardPath() { FindFile ff = new WildcardFindFile() .include("**/file/*") .recursive(true) .includeDirs(true) .searchPath(dataRoot); int countDirs = 0; int countFiles = 0; File f; while ((f = ff.nextFile()) != null) { if (f.isDirectory()) { countDirs++; } else { countFiles++; String path = f.getAbsolutePath(); path = FileNameUtil.separatorsToUnix(path); if (!path.startsWith("/")) { path = '/' + path; } boolean matched = path.equals(dataRoot + "/file/a.png") || path.equals(dataRoot + "/file/a.txt"); assertTrue(matched); } } assertEquals(0, countDirs); assertEquals(2, countFiles); }
@Test void testRegexp() { FindFile ff = FindFile.createRegExpFF() .include(".*/a[.].*") .recursive(true) .includeDirs(true) .searchPath(dataRoot); int countDirs = 0; int countFiles = 0; File f; while ((f = ff.nextFile()) != null) { if (f.isDirectory()) { countDirs++; } else { countFiles++; String path = f.getAbsolutePath(); path = FileNameUtil.separatorsToUnix(path); if (!path.startsWith("/")) { path = '/' + path; } boolean matched = path.equals(dataRoot + "/file/a.png") || path.equals(dataRoot + "/file/a.txt"); assertTrue(matched); } } assertEquals(0, countDirs); assertEquals(2, countFiles); }
ff.searchPath(root); File file; while ((file = ff.nextFile()) != null) { processed = true; System.out.println('+' + file.getName());
@Test void testDecoraParser() throws IOException { DecoraParser decoraParser = new DecoraParser(); FindFile ff = new WildcardFindFile().include("*.*ml"); ff.matchType(FindFile.Match.NAME); ff.searchPath(testDataRoot); File file; while ((file = ff.nextFile()) != null) { System.out.println("+" + file.getName()); char[] page = FileUtil.readString(file).toCharArray(); String decoratorFileName = StringUtil.replace(file.getAbsolutePath(), ".html", "-decora.htm"); char[] decorator = FileUtil.readString(decoratorFileName).toCharArray(); FastCharArrayWriter writer = new FastCharArrayWriter(); decoraParser.decorate(writer, page, decorator); String out = writer.toString(); String outFileName = StringUtil.replace(file.getAbsolutePath(), ".html", "-out.htm"); String outExpected = FileUtil.readString(outFileName); assertEquals(trimLines(outExpected), trimLines(out)); } }
while ((f = ff.nextFile()) != null) { if (f.isDirectory()) { countDirs++;
@Test void testTwoRoots() { FindFile ff = new WildcardFindFile() .includeDirs(true) .includeFiles(true) .recursive(true) .walking(true) .searchPath(dataRoot + "/beta") .searchPath(dataRoot + "/sumo") .include("**"); int count = 0; while (ff.nextFile() != null) { count++; } assertEquals(5, count); ff.reset(); ff.includeDirs(false); count = 0; while (ff.nextFile() != null) { count++; } assertEquals(3, count); }
@Test void testNonExisting() { FindFile wff = new FindFile(); wff.includeDirs(true); wff.includeFiles(true); wff.recursive(true); wff.walking(true); wff.searchPath(dataRoot + "/void"); wff.matchType(WildcardFindFile.Match.FULL_PATH); int count = 0; while (wff.nextFile() != null) { count++; } assertEquals(0, count); }
/** * Finds all files and returns list of founded files. */ public List<File> findAll() { List<File> allFiles = new ArrayList<>(); File file; while ((file = nextFile()) != null) { allFiles.add(file); } return allFiles; }