Commit ba16edd9 authored by Tatyana's avatar Tatyana 👽

FileMonitor & FileSearcher garbage comments removed

parent daf90e1b
......@@ -20,7 +20,7 @@ public class FileMonitor extends Thread {
private final boolean recursive;
@SuppressWarnings("unchecked")
static <T> WatchEvent<T> cast(WatchEvent<?> event) {
private static <T> WatchEvent<T> cast(WatchEvent<?> event) {
return (WatchEvent<T>) event;
}
......@@ -31,14 +31,6 @@ public class FileMonitor extends Thread {
this.recursive = recursive;
this.fileSearcher = fileSearcher;
/*if (recursive) {
System.out.format("Scanning %s ...\n", dir);
registerAll(dir);
System.out.println("Done.");
} else {
register(dir);
}*/
// enable trace after initial registration
this.trace = true;
}
......@@ -61,67 +53,6 @@ public class FileMonitor extends Thread {
keys.put(key, dir);
}
/*public static synchronized FileMonitor getInstance() {
if (instance == null) {
try {
instance = new FileMonitor();
} catch (IOException e) {
System.out.println("Error while initializing monitor occured");
return null;
}
}
return instance;
}*/
/* public void registerDir(Path newDir) {
proceed = true;
try {
keys.add(newDir.register(watcher,
ENTRY_CREATE,
ENTRY_DELETE
*//*ENTRY_MODIFY*//*));
} catch (IOException x) {
System.err.println(x);
}
}*/
/*public void run() {
fileSearcher = FileSearcher.getInstance();
while (proceed) {
WatchKey key;
try {
key = watcher.take();
} catch (InterruptedException x) {
return;
}
for (WatchEvent<?> event : key.pollEvents()) {
WatchEvent.Kind<?> kind = event.kind();
if (kind == OVERFLOW) {
continue;
}
WatchEvent<Path> ev = (WatchEvent<Path>) event;
Path dir = (Path) key.watchable();
Path filename = dir.resolve(ev.context());
*//*if (kind == ENTRY_CREATE) {
fileSearcher.addFile(filename.toAbsolutePath().toFile());
System.out.println("CREATE - " + filename.toAbsolutePath().toFile().toString());
}
if (kind == ENTRY_DELETE) {*//*
fileSearcher.addFile(filename.toAbsolutePath().toFile());
System.out.println("MONITOR FOUNDED FILE - " + filename.toAbsolutePath().toFile().toString());
*//*}*//*
}
}
}*/
/**
* Register the given directory, and all its sub-directories, with the
* WatchService.
......@@ -147,7 +78,7 @@ public class FileMonitor extends Thread {
processEvents();
}
void processEvents() {
private void processEvents() {
for (; ; ) {
// wait for key to be signalled
......@@ -181,9 +112,9 @@ public class FileMonitor extends Thread {
// print out event
System.out.format("%s: %s\n", event.kind().name(), child);
if (event.kind().name().equals(ENTRY_CREATE))
if (event.kind() == ENTRY_CREATE)
fileSearcher.addFile(child.toAbsolutePath().toFile());
if (event.kind().name().equals(ENTRY_DELETE))
if (event.kind() == ENTRY_DELETE)
fileSearcher.removeFile(child.toAbsolutePath().toFile());
// if directory is created, and watching recursively, then
......
......@@ -25,7 +25,7 @@ public class FileSearcher {
try {
monitor = new FileMonitor(instance, true);
} catch (IOException e) {
System.out.println("Problem encountered during creating MONITOR.");
System.out.println("ERROR : A problem encountered during creating MONITOR.");
}
if (monitor != null) {
......@@ -39,12 +39,21 @@ public class FileSearcher {
return FileVisitResult.CONTINUE;
}
/*
* Здесь был найден файл (он может также быть архивом)
* но сейчас нет разницы - обычный это файл или архив
* */
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
foundedFiles.add(file.toFile());
return FileVisitResult.CONTINUE;
}
/*
* Здесь могла случиться проблема с открытием файла.
* Это подойдет в том случае, если архив запаролен
*
*/
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
return FileVisitResult.CONTINUE;
......@@ -56,12 +65,13 @@ public class FileSearcher {
}
});
} catch (IOException e) {
System.out.println("Problem encountered during walking.");
System.out.println("ERROR : A problem encountered during walking through directories.");
} finally {
monitor.finishMonitoring();
}
foundedFiles.addAll(monitoredFiles);
filesFound += monitoredFiles.size();
}
return foundedFiles;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment