Implement JSON file parser
This commit is contained in:
parent
300b7b78ee
commit
80d7675059
|
@ -2,12 +2,19 @@ package org.RI.P2;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.json.simple.JSONArray;
|
||||||
|
import org.json.simple.JSONValue;
|
||||||
|
import org.json.simple.parser.ParseException;
|
||||||
|
|
||||||
public class Parser {
|
public class Parser {
|
||||||
private static List<File> files;
|
private static List<File> files;
|
||||||
|
|
||||||
|
@ -16,17 +23,17 @@ public class Parser {
|
||||||
.collect(Collectors.toList());
|
.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() {
|
private static void usage() {
|
||||||
System.out.println("Usage: Parser <directory>");
|
System.out.println("Usage: Parser <directory>");
|
||||||
System.out.println("option directory: directory that contains JSON files");
|
System.out.println("option directory: directory that contains JSON files");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
|
||||||
if (args.length != 1) {
|
|
||||||
usage();
|
|
||||||
}
|
|
||||||
String directory = args[0];
|
|
||||||
readFiles(directory);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue