diff --git a/src/main/java/org/RI/P2/Parser.java b/src/main/java/org/RI/P2/Parser.java index 642b190..ba5afca 100644 --- a/src/main/java/org/RI/P2/Parser.java +++ b/src/main/java/org/RI/P2/Parser.java @@ -2,12 +2,19 @@ package org.RI.P2; import java.util.List; import java.io.IOException; +import java.io.Reader; +import java.io.InputStream; +import java.io.InputStreamReader; import java.io.File; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.stream.Collectors; +import org.json.simple.JSONArray; +import org.json.simple.JSONValue; +import org.json.simple.parser.ParseException; + public class Parser { private static List files; @@ -16,17 +23,17 @@ public class Parser { .collect(Collectors.toList()); } + public JSONArray parseJSONFile(String filePath) throws IOException, ParseException { + InputStream jsonFile = getClass().getResourceAsStream(filePath); + Reader readerJson = new InputStreamReader(jsonFile); + Object fileObjects = JSONValue.parseWithException(readerJson); + JSONArray arrayObjects = (JSONArray) fileObjects; + return arrayObjects; + } + private static void usage() { System.out.println("Usage: Parser "); System.out.println("option directory: directory that contains JSON files"); System.exit(1); } - - public static void main(String[] args) throws IOException { - if (args.length != 1) { - usage(); - } - String directory = args[0]; - readFiles(directory); - } }