@Test @PrepareForTest(File.class) public void testRake() { final File base = mock(File.class); final FileWatcher fileWatcher = new FileWatcher(base); final HashSet<File> checked = new HashSet<>(); final HashSet<File> changed = new HashSet<>(); fileWatcher.rake(checked, changed); }
protected void rake(final Set<File> checked, final Set<File> changed) { logger.trace("Base: {}", base); logger.trace("Base's last modified: {}", lastModified); long max = 0; final Queue<File> files = new LinkedList<>(asList(base)); while (!files.isEmpty()) { final File file = files.remove(); logger.trace("File: {}", file); final long lastModifiedInFile = file.lastModified(); max = Math.max(lastModifiedInFile, max); if (lastModified < lastModifiedInFile) { changed.add(file); } checked.add(file); final File[] children = nvl(file.listFiles(), new File[0]); logger.trace("Find {} files", children.length); files.addAll(stream(children) .filter(child -> !ignores.contains(child.getName())).collect(toList())); } lastModified = max; }
FileWatcher extends ThreadServer implements Runnable { protected void rake(final Set<File> checked, final Set<File> changed) { logger.trace("Base: {}", base); logger.trace("Base's last modified: {}", lastModified); long max = 0; final Queue<File> files = new LinkedList<>(asList(base)); while (!files.isEmpty()) { final File file = files.remove(); logger.trace("File: {}", file); final long lastModifiedInFile = file.lastModified(); max = Math.max(lastModifiedInFile, max); if (lastModified < lastModifiedInFile) { changed.add(file); } checked.add(file); final File[] children = nvl(file.listFiles(), new File[0]); logger.trace("Find {} files", children.length); files.addAll(stream(children) .filter(child -> !ignores.contains(child.getName())).collect(toList())); } lastModified = max; } }
FileWatcher extends ThreadServer implements Runnable { protected void rake(final Set<File> checked, final Set<File> changed) { logger.trace("Base: {}", base); logger.trace("Base's last modified: {}", lastModified); long max = 0; final Queue<File> files = new LinkedList<>(asList(base)); while (!files.isEmpty()) { final File file = files.remove(); logger.trace("File: {}", file); final long lastModifiedInFile = file.lastModified(); max = Math.max(lastModifiedInFile, max); if (lastModified < lastModifiedInFile) { changed.add(file); } checked.add(file); final File[] children = nvl(file.listFiles(), new File[0]); logger.trace("Find {} files", children.length); files.addAll(stream(children) .filter(child -> !ignores.contains(child.getName())).collect(toList())); } lastModified = max; } FileWatcher(final File basePath); }
FileWatcher extends ThreadServer implements Runnable { protected void rake(final Set<File> checked, final Set<File> changed) { logger.trace("Base: {}", base); logger.trace("Base's last modified: {}", lastModified); long max = 0; final Queue<File> files = new LinkedList<>(asList(base)); while (!files.isEmpty()) { final File file = files.remove(); logger.trace("File: {}", file); final long lastModifiedInFile = file.lastModified(); max = Math.max(lastModifiedInFile, max); if (lastModified < lastModifiedInFile) { changed.add(file); } checked.add(file); final File[] children = nvl(file.listFiles(), new File[0]); logger.trace("Find {} files", children.length); files.addAll(stream(children) .filter(child -> !ignores.contains(child.getName())).collect(toList())); } lastModified = max; } FileWatcher(final File basePath); void addIgnore(final String name); }
FileWatcher extends ThreadServer implements Runnable { protected void rake(final Set<File> checked, final Set<File> changed) { logger.trace("Base: {}", base); logger.trace("Base's last modified: {}", lastModified); long max = 0; final Queue<File> files = new LinkedList<>(asList(base)); while (!files.isEmpty()) { final File file = files.remove(); logger.trace("File: {}", file); final long lastModifiedInFile = file.lastModified(); max = Math.max(lastModifiedInFile, max); if (lastModified < lastModifiedInFile) { changed.add(file); } checked.add(file); final File[] children = nvl(file.listFiles(), new File[0]); logger.trace("Find {} files", children.length); files.addAll(stream(children) .filter(child -> !ignores.contains(child.getName())).collect(toList())); } lastModified = max; } FileWatcher(final File basePath); void addIgnore(final String name); static final int RESET; static final int FILE_ADDED; static final int FILE_REMOVED; static final int FILE_CHANGED; static final int ANY_CHANGED; }