diff --git a/src/main/java/org/RI/P1/TODO.org b/TODO.org similarity index 100% rename from src/main/java/org/RI/P1/TODO.org rename to TODO.org diff --git a/pom.xml b/pom.xml index e6a0303..5e39ac8 100644 --- a/pom.xml +++ b/pom.xml @@ -14,8 +14,8 @@ UTF-8 - 1.7 - 1.7 + 1.8 + 1.8 diff --git a/src/main/java/org/RI/P1/AnalyzeDirectory.java b/src/main/java/org/RI/P1/AnalyzeDirectory.java new file mode 100644 index 0000000..f11e598 --- /dev/null +++ b/src/main/java/org/RI/P1/AnalyzeDirectory.java @@ -0,0 +1,32 @@ +package org.RI.P1; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; +import java.util.stream.Collectors; + +import org.apache.tika.exception.TikaException; +import org.xml.sax.SAXException; + +public class AnalyzeDirectory { + private static List files; + + private static void readFiles(String directory) throws IOException { + files = Files.walk(Paths.get(directory)).filter(Files::isRegularFile).map(Path::toFile) + .collect(Collectors.toList()); + } + + public static void main(String[] args) throws IOException, TikaException, SAXException { + String directory = args[0]; + readFiles(directory); + for (File file : files) { + FileData data = new FileData(file); + System.out.println(data); + System.out.println("--------------------------------------------------------------------------"); + } + } + +} diff --git a/src/main/java/org/RI/P1/FileData.java b/src/main/java/org/RI/P1/FileData.java index 4b33451..229e590 100644 --- a/src/main/java/org/RI/P1/FileData.java +++ b/src/main/java/org/RI/P1/FileData.java @@ -30,13 +30,14 @@ public class FileData { FileData() { } - FileData(File file) throws FileNotFoundException { + FileData(File file) throws IOException, TikaException, SAXException { inputStream = new FileInputStream(file); metadata = new Metadata(); parser = new AutoDetectParser(); contentHandler = new BodyContentHandler(-1); parseContext = new ParseContext(); langIdentifier = new OptimaizeLangDetector().loadModels(); + setMetadata(); } private void setMetadata() throws IOException, TikaException, SAXException { @@ -53,14 +54,4 @@ public class FileData { + language.getLanguage() + "\n"; } - public static void main(String[] args) throws IOException, TikaException, SAXException { - try { - File file = new File(args[0]); - FileData data = new FileData(file); - data.setMetadata(); - System.out.println(data); - } catch (FileNotFoundException exp) { - System.out.println("The file " + args[0] + " could not be found"); - } - } }