Commit 55395dbe authored by Rina Sergeeva's avatar Rina Sergeeva

fix

parents 42dec140 a4106066
......@@ -10,8 +10,8 @@ import static java.nio.file.StandardWatchEventKinds.*;
public class FileMonitor extends Thread {
private FileSearcher fileSearcher;
private WatchService watcher = FileSystems.getDefault().newWatchService();
private boolean proceed = false;
private ArrayList<WatchKey> keys = new ArrayList<>();
private boolean proceed = false;
private static FileMonitor instance;
......@@ -32,13 +32,14 @@ public class FileMonitor extends Thread {
}
public void registerDir(File newDir) {
proceed = true;
try {
proceed = true;
Path dir = Paths.get(newDir.getAbsolutePath());
keys.add(dir.register(watcher,
ENTRY_CREATE,
ENTRY_DELETE
/*ENTRY_MODIFY*/));
System.out.println("MONITOR ::: DIR REGISTERED" + newDir);
} catch (IOException x) {
System.err.println(x);
}
......@@ -50,10 +51,11 @@ public class FileMonitor extends Thread {
key.cancel();
}
keys.clear();
System.out.println("Stop monitor thread!");
System.out.println("MONITOR ::: STOPPED");
}
public void run() {
System.out.println("MONITOR ::: STARTING");
fileSearcher = FileSearcher.getInstance();
while (proceed) {
......@@ -76,13 +78,20 @@ public class FileMonitor extends Thread {
Path filename = dir.resolve(ev.context());
if (kind == ENTRY_CREATE) {
fileSearcher.addFile(filename.toAbsolutePath().toFile());
File file = filename.toAbsolutePath().toFile();
if (!file.isDirectory()) {
fileSearcher.addFile(filename.toAbsolutePath().toFile());
System.out.println("ADD FILE - " + filename.toAbsolutePath().toFile().toString());
}
}
if (kind == ENTRY_DELETE) {
fileSearcher.removeFile(filename.toAbsolutePath().toFile());
File file = filename.toAbsolutePath().toFile();
if (!file.isDirectory()) {
fileSearcher.removeFile(filename.toAbsolutePath().toFile());
System.out.println("DELETE FILE - " + filename.toAbsolutePath().toFile().toString());
}
}
}
}
}
}
......@@ -20,10 +20,12 @@ public class FileSearcher {
if (monitor != null) {
monitor.setName("Monitor Thread");
monitor.start();
monitor.registerDir(root);
monitor.start();
foundedFiles = scanDirectory(root);
System.out.println("Add monitored files");
foundedFiles.addAll(monitoredFiles);
monitor.stopMonitoring();
......
......@@ -24,6 +24,8 @@ public class UnzipUtil {
if(!unzipDir.mkdirs()){
System.out.println("Directory " + unzipDir +" does not created!");
}else{
FileMonitor monitor = FileMonitor.getInstance();
monitor.registerDir(unzipDir);
unzipDirs.add(unzipDir);
}
......@@ -43,6 +45,7 @@ public class UnzipUtil {
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Unzip " + unzipDir);
}
static boolean isZip(File file) {
......
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