diff --git a/parsers/test_java_opack_0_2_1/META-INF/MANIFEST.MF b/parsers/test_java_opack_0_2_1/META-INF/MANIFEST.MF new file mode 100644 index 0000000..18bd115 --- /dev/null +++ b/parsers/test_java_opack_0_2_1/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: TestJSONParsing +Class-Path: opack-0.2.1.jar diff --git a/parsers/test_java_opack_0_2_1/README.txt b/parsers/test_java_opack_0_2_1/README.txt new file mode 100644 index 0000000..58ae2a0 --- /dev/null +++ b/parsers/test_java_opack_0_2_1/README.txt @@ -0,0 +1,5 @@ +javac -cp opack-0.2.1.jar TestJSONParsing.java + +jar cvfm TestJSONParsing.jar META-INF/MANIFEST.MF opack-0.2.1.jar TestJSONParsing.class + +java -jar TestJSONParsing.jar diff --git a/parsers/test_java_opack_0_2_1/TestJSONParsing.class b/parsers/test_java_opack_0_2_1/TestJSONParsing.class new file mode 100644 index 0000000..dcb0262 Binary files /dev/null and b/parsers/test_java_opack_0_2_1/TestJSONParsing.class differ diff --git a/parsers/test_java_opack_0_2_1/TestJSONParsing.jar b/parsers/test_java_opack_0_2_1/TestJSONParsing.jar new file mode 100644 index 0000000..621f5ee Binary files /dev/null and b/parsers/test_java_opack_0_2_1/TestJSONParsing.jar differ diff --git a/parsers/test_java_opack_0_2_1/TestJSONParsing.java b/parsers/test_java_opack_0_2_1/TestJSONParsing.java new file mode 100644 index 0000000..ee43065 --- /dev/null +++ b/parsers/test_java_opack_0_2_1/TestJSONParsing.java @@ -0,0 +1,81 @@ +import com.realtimetech.opack.codec.json.Json; +import com.realtimetech.opack.exception.DecodeException; +import com.realtimetech.opack.value.OpackValue; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +public class TestJSONParsing { + public static String readFileAutoDetect(Path path) throws IOException { + try (InputStream inputStream = Files.newInputStream(path); + BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream)) { + + bufferedInputStream.mark(4); + + byte[] bom = new byte[4]; + int read = bufferedInputStream.read(bom, 0, bom.length); + + Charset encoding; + int bomLength = 0; + + if (read >= 3 && bom[0] == (byte) 0xEF && bom[1] == (byte) 0xBB && bom[2] == (byte) 0xBF) { + encoding = StandardCharsets.UTF_8; + bomLength = 3; + } else if (read >= 2 && bom[0] == (byte) 0xFE && bom[1] == (byte) 0xFF) { + encoding = StandardCharsets.UTF_16BE; + bomLength = 2; + } else if (read >= 2 && bom[0] == (byte) 0xFF && bom[1] == (byte) 0xFE) { + encoding = StandardCharsets.UTF_16LE; + bomLength = 2; + } else { + encoding = StandardCharsets.UTF_8; + } + + bufferedInputStream.reset(); + bufferedInputStream.skip(bomLength); + + return new String(bufferedInputStream.readAllBytes(), encoding); + } + } + + public static boolean isValidJSON(String jsonString) { + try { + Object object = Json.decodeObject(jsonString); + + System.out.println(object); + + return true; + } catch (DecodeException exception) { + exception.printStackTrace(); + return false; + } + } + + public static void main(String[] args) { + if (args.length == 0) { + System.out.println("Usage: java TestJSONParsing file.json"); + System.exit(2); + } + + try { + String jsonString = readFileAutoDetect(Paths.get(args[0])); + + if (isValidJSON(jsonString)) { + System.out.println("valid"); + System.exit(0); + } + + System.out.println("invalid"); + System.exit(1); + } catch (IOException exception) { + System.out.println("not found"); + System.exit(2); + } + } +} diff --git a/parsers/test_java_opack_0_2_1/opack-0.2.1.jar b/parsers/test_java_opack_0_2_1/opack-0.2.1.jar new file mode 100644 index 0000000..73996bc Binary files /dev/null and b/parsers/test_java_opack_0_2_1/opack-0.2.1.jar differ diff --git a/run_tests.py b/run_tests.py index 462edb6..d4def76 100755 --- a/run_tests.py +++ b/run_tests.py @@ -432,6 +432,11 @@ "url":"https://github.com/michel-kraemer/actson", "commands":["/usr/bin/java", "-jar", os.path.join(PARSERS_DIR, "test_java_actson_1_2_0/TestJSONParsing.jar")] }, + "Java Opack 0.2.1": + { + "url": "https://github.com/realtimetech-solution/opack", + "commands": ["/usr/bin/java", "-jar", os.path.join(PARSERS_DIR, "test_java_opack_0_2_1/TestJSONParsing.jar")] + }, "Haskell Aeson 0.11.2.1": { "url":"https://github.com/bos/aeson",