Commit 2d7e082d authored by Rina Sergeeva's avatar Rina Sergeeva

added logger

parent a3fdc34e
......@@ -47,9 +47,11 @@ public class FileSearcher {
* */
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
foundedFiles.add(file.toFile());
// if(UnzipUtil.isZip(file.toFile())){
// UnzipUtil.unzipArchive(file.toFile());
if(UnzipUtil.isZip(file.toFile())) {
UnzipUtil.unzipArchive(file.toFile());
}else{
foundedFiles.add(file.toFile());
}
filesCounter.incrementAndGet();
return FileVisitResult.CONTINUE;
}
......
package application.util;
import eu.medsea.mimeutil.MimeUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.*;
import java.util.ArrayList;
......@@ -12,21 +14,20 @@ import java.util.zip.ZipFile;
public class UnzipUtil {
private static ArrayList<File> unzipDirs = new ArrayList<>();
static Logger logger = LogManager.getLogger(FileMonitor.class);
public static void unzipArchive(File archive) {
if (!archive.exists() || !archive.canRead()) {
System.out.println("Archive cannot be unzip!");
logger.error("Archive cannot be unzip!");
return;
}
File unzipDir = new File(archive.getParent(), archive.getName().substring(0, archive.getName().lastIndexOf(".")));
if(!unzipDir.mkdirs()){
System.out.println("Directory " + unzipDir +" does not created!");
logger.error("Directory " + unzipDir +" does not created!");
}else{
FileMonitor monitor = FileMonitor.getInstance();
monitor.registerDir(unzipDir);
unzipDirs.add(unzipDir);
unzipDirs.add(0, unzipDir);
}
try (ZipFile zip = new ZipFile(archive)) {
......@@ -41,11 +42,14 @@ public class UnzipUtil {
write(zip.getInputStream(entry),
new BufferedOutputStream(new FileOutputStream(entryUnzipFile)));
}
if(isZip(entryUnzipFile)){
unzipArchive(entryUnzipFile);
}
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Unzip " + unzipDir);
logger.info("Unzip " + unzipDir);
}
static boolean isZip(File file) {
......@@ -66,6 +70,6 @@ public class UnzipUtil {
}
public static void deleteUnzipFiles(){
unzipDirs.forEach((p) ->{if(!p.delete()){System.out.print("Directory " + p + " does not deleted!");}});
unzipDirs.forEach((p) ->{if(!p.delete()){logger.error("Directory " + p + " does not deleted!");}});
}
}
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