From 146828ef151a8846b86635e6cb912ea7886e831e Mon Sep 17 00:00:00 2001 From: Stephanie Gawroriski Date: Wed, 13 Jul 2022 02:24:51 +0000 Subject: [PATCH] Corrections to JSON; Add tests for parsing and writing JSON; Implement some missing methods in AbstractMap, Writer, and OutputStreamWriter. --- .../cc/squirreljme/jvm/manifest/JavaManifest.java | 1 + .../jvm/manifest/JavaManifestAttributes.java | 1 + .../squirreljme/runtime/cldc/io/CodecFactory.java | 5 +- .../io/{IBM037Encoder.java => IBM037Base.java} | 42 +---- .../squirreljme/runtime/cldc/io/IBM037Decoder.java | 33 ++++ .../squirreljme/runtime/cldc/io/IBM037Encoder.java | 58 +------ .../runtime/cldc/io/PrintStreamWriter.java | 3 + .../squirreljme/runtime/cldc/io/ShiftJisBase.java | 49 ++++++ .../runtime/cldc/io/ShiftJisDecoder.java | 35 +--- .../runtime/cldc/io/ShiftJisEncoder.java | 33 ++++ .../squirreljme/runtime/cldc/util/EnumTypeMap.java | 1 + .../runtime/cldc/util/SortedTreeMap.java | 1 + .../src/main/java/java/io/BufferedWriter.java | 6 + .../src/main/java/java/io/OutputStreamWriter.java | 156 +++++++++++++++--- .../cldc-compact/src/main/java/java/io/Reader.java | 7 +- .../cldc-compact/src/main/java/java/io/Writer.java | 182 ++++++++++++++++----- .../src/main/java/java/util/AbstractMap.java | 32 +++- .../src/main/java/java/util/AbstractSet.java | 3 +- .../src/main/java/java/util/HashMap.java | 1 + .../src/main/java/java/util/Hashtable.java | 1 + .../cldc-compact/src/main/java/java/util/Map.java | 9 +- .../src/main/java/java/util/WeakHashMap.java | 2 +- .../src/test/java/io/TestXStreamRW.java | 80 +++++++++ .../src/test/resources/io/TestXStreamRW.in | 5 + .../src/test/resources/io/TestXStreamRW@ascii.in | 10 ++ .../src/test/resources/io/TestXStreamRW@ibm037.in | 10 ++ .../test/resources/io/TestXStreamRW@iso-8859-1.in | 9 + .../test/resources/io/TestXStreamRW@iso-8859-15.in | 9 + .../test/resources/io/TestXStreamRW@shift-jis.in | 11 ++ .../src/test/resources/io/TestXStreamRW@utf-8.in | 12 ++ .../net/multiphasicapps/collections/EmptyMap.java | 1 + .../multiphasicapps/collections/IdentityMap.java | 1 + .../collections/UnmodifiableMap.java | 1 + .../java/cc/squirreljme/jdwp/__QuickTable__.java | 1 + .../multiphasicapps/jsr353/ImplMegaFactory.java | 2 +- .../json/src/test/java/TestGenerateSameJson.java | 65 ++++++++ modules/json/src/test/java/TestJsonParse.java | 72 ++++++++ .../src/test/resources/TestGenerateSameJson.in | 3 + modules/json/src/test/resources/TestJsonParse.in | 22 +++ modules/json/src/test/resources/sample.json | 18 ++ 40 files changed, 790 insertions(+), 203 deletions(-) copy modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/{IBM037Encoder.java => IBM037Base.java} (72%) create mode 100644 modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/IBM037Decoder.java create mode 100644 modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/ShiftJisBase.java create mode 100644 modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/ShiftJisEncoder.java create mode 100644 modules/cldc-compact/src/test/java/io/TestXStreamRW.java create mode 100644 modules/cldc-compact/src/test/resources/io/TestXStreamRW.in create mode 100644 modules/cldc-compact/src/test/resources/io/TestXStreamRW@ascii.in create mode 100644 modules/cldc-compact/src/test/resources/io/TestXStreamRW@ibm037.in create mode 100644 modules/cldc-compact/src/test/resources/io/TestXStreamRW@iso-8859-1.in create mode 100644 modules/cldc-compact/src/test/resources/io/TestXStreamRW@iso-8859-15.in create mode 100644 modules/cldc-compact/src/test/resources/io/TestXStreamRW@shift-jis.in create mode 100644 modules/cldc-compact/src/test/resources/io/TestXStreamRW@utf-8.in create mode 100644 modules/json/src/test/java/TestGenerateSameJson.java create mode 100644 modules/json/src/test/java/TestJsonParse.java create mode 100644 modules/json/src/test/resources/TestGenerateSameJson.in create mode 100644 modules/json/src/test/resources/TestJsonParse.in create mode 100644 modules/json/src/test/resources/sample.json diff --git a/modules/cldc-compact/src/main/java/cc/squirreljme/jvm/manifest/JavaManifest.java b/modules/cldc-compact/src/main/java/cc/squirreljme/jvm/manifest/JavaManifest.java index 8358ad7972..1322fc581a 100644 --- a/modules/cldc-compact/src/main/java/cc/squirreljme/jvm/manifest/JavaManifest.java +++ b/modules/cldc-compact/src/main/java/cc/squirreljme/jvm/manifest/JavaManifest.java @@ -228,6 +228,7 @@ public final class JavaManifest /** * {@inheritDoc} * @since 2016/05/20 + * @param __k */ @Override public JavaManifestAttributes get(Object __k) diff --git a/modules/cldc-compact/src/main/java/cc/squirreljme/jvm/manifest/JavaManifestAttributes.java b/modules/cldc-compact/src/main/java/cc/squirreljme/jvm/manifest/JavaManifestAttributes.java index 82b74a08a7..107ed133ef 100644 --- a/modules/cldc-compact/src/main/java/cc/squirreljme/jvm/manifest/JavaManifestAttributes.java +++ b/modules/cldc-compact/src/main/java/cc/squirreljme/jvm/manifest/JavaManifestAttributes.java @@ -103,6 +103,7 @@ public final class JavaManifestAttributes /** * {@inheritDoc} * @since 2016/05/20 + * @param __o */ @Override public String get(Object __o) diff --git a/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/CodecFactory.java b/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/CodecFactory.java index 46a6ef0d2a..32794d1e82 100644 --- a/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/CodecFactory.java +++ b/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/CodecFactory.java @@ -52,7 +52,7 @@ public final class CodecFactory return new ASCIIDecoder(); case BuiltInEncodingType.IBM037: - throw Debugging.todo(); + return new IBM037Decoder(); case BuiltInEncodingType.ISO_8859_1: return new ISO88591Decoder(); @@ -154,6 +154,9 @@ public final class CodecFactory case BuiltInEncodingType.ISO_8859_15: return new ISO885915Encoder(); + case BuiltInEncodingType.SHIFT_JIS: + return new ShiftJisEncoder(); + case BuiltInEncodingType.UTF8: return new UTF8Encoder(); diff --git a/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/IBM037Encoder.java b/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/IBM037Base.java similarity index 72% copy from modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/IBM037Encoder.java copy to modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/IBM037Base.java index 8fb3f993ca..a1071eb9d2 100644 --- a/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/IBM037Encoder.java +++ b/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/IBM037Base.java @@ -1,6 +1,6 @@ // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*- // --------------------------------------------------------------------------- -// SquirrelJME +// Multi-Phasic Applications: SquirrelJME // Copyright (C) Stephanie Gawroriski // --------------------------------------------------------------------------- // SquirrelJME is under the GNU General Public License v3+, or later. @@ -10,15 +10,15 @@ package cc.squirreljme.runtime.cldc.io; /** - * Encodes to EBCDIC IBM037. + * Base class for IBM037. * - * @since 2018/09/24 + * @since 2022/07/12 */ -public final class IBM037Encoder - implements Encoder +public abstract class IBM037Base + implements NamedCodec { /** Mapping of char to byte. */ - private static final byte[] _MAP = + static final byte[] _MAP = new byte[] { 0, 1, 2, 3, 55, 45, 46, 47, 22, 5, 37, 11, 12, 13, 14, 15, 16, 17, @@ -54,35 +54,6 @@ public final class IBM037Encoder /** * {@inheritDoc} - * @since 2018/09/24 - */ - @Override - public final int encode(char __c, byte[] __b, int __o, int __l) - throws IndexOutOfBoundsException, NullPointerException - { - if (__b == null) - throw new NullPointerException("NARG"); - if (__o < 0 || __l < 0 || (__o + __l) < 0 || (__o + __l) > __b.length) - throw new IndexOutOfBoundsException("IOOB"); - - // Always encodes to one character, so if one character cannot fit in - // the buffer then fail - if (__l < 1) - return -1; - - // Invalid characters are turned into question marks - if (__c >= 0x100) - __c = '?'; - - // Map - __b[__o] = IBM037Encoder._MAP[__c]; - - // Only single characters written - return 1; - } - - /** - * {@inheritDoc} * @since 2018/10/13 */ @Override @@ -101,4 +72,3 @@ public final class IBM037Encoder return 1; } } - diff --git a/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/IBM037Decoder.java b/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/IBM037Decoder.java new file mode 100644 index 0000000000..3faf35cc41 --- /dev/null +++ b/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/IBM037Decoder.java @@ -0,0 +1,33 @@ +// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*- +// --------------------------------------------------------------------------- +// Multi-Phasic Applications: SquirrelJME +// Copyright (C) Stephanie Gawroriski +// --------------------------------------------------------------------------- +// SquirrelJME is under the GNU General Public License v3+, or later. +// See license.mkd for licensing and copyright information. +// --------------------------------------------------------------------------- + +package cc.squirreljme.runtime.cldc.io; + +import cc.squirreljme.runtime.cldc.debug.Debugging; + +/** + * Decoder for IBM 037, aka EBCDIC. + * + * @since 2022/07/12 + */ +public class IBM037Decoder + extends IBM037Base + implements Decoder +{ + /** + * {@inheritDoc} + * @since 2022/07/12 + */ + @Override + public int decode(byte[] __b, int __o, int __l) + throws IndexOutOfBoundsException, NullPointerException + { + throw Debugging.todo(); + } +} diff --git a/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/IBM037Encoder.java b/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/IBM037Encoder.java index 8fb3f993ca..95649be41e 100644 --- a/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/IBM037Encoder.java +++ b/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/IBM037Encoder.java @@ -15,43 +15,9 @@ package cc.squirreljme.runtime.cldc.io; * @since 2018/09/24 */ public final class IBM037Encoder + extends IBM037Base implements Encoder { - /** Mapping of char to byte. */ - private static final byte[] _MAP = - new byte[] - { - 0, 1, 2, 3, 55, 45, 46, 47, 22, 5, 37, 11, 12, 13, 14, 15, 16, 17, - 18, 19, 60, 61, 50, 38, 24, 25, 63, 39, 28, 29, 30, 31, 64, 90, - 127, 123, 91, 108, 80, 125, 77, 93, 92, 78, 107, 96, 75, 97, -16, - -15, -14, -13, -12, -11, -10, -9, -8, -7, 122, 94, 76, 126, 110, - 111, 124, -63, -62, -61, -60, -59, -58, -57, -56, -55, -47, -46, - -45, -44, -43, -42, -41, -40, -39, -30, -29, -28, -27, -26, -25, - -24, -23, -70, -32, -69, -80, 109, 121, -127, -126, -125, -124, - -123, -122, -121, -120, -119, -111, -110, -109, -108, -107, -106, - -105, -104, -103, -94, -93, -92, -91, -90, -89, -88, -87, -64, 79, - -48, -95, 7, 32, 33, 34, 35, 36, 0, 6, 23, 40, 41, 42, 43, 44, 9, - 10, 27, 48, 49, 26, 51, 52, 53, 54, 8, 56, 57, 58, 59, 4, 20, 62, - -1, 65, -86, 74, -79, -97, -78, 106, -75, -67, -76, -102, -118, 95, - -54, -81, -68, -112, -113, -22, -6, -66, -96, -74, -77, -99, -38, - -101, -117, -73, -72, -71, -85, 100, 101, 98, 102, 99, 103, -98, - 104, 116, 113, 114, 115, 120, 117, 118, 119, -84, 105, -19, -18, - -21, -17, -20, -65, -128, -3, -2, -5, -4, -83, -82, 89, 68, 69, 66, - 70, 67, 71, -100, 72, 84, 81, 82, 83, 88, 85, 86, 87, -116, 73, - -51, -50, -53, -49, -52, -31, 112, -35, -34, -37, -36, -115, -114, - -33 - }; - - /** - * {@inheritDoc} - * @since 2018/12/08 - */ - @Override - public final double averageSequenceLength() - { - return 1.0; - } - /** * {@inheritDoc} * @since 2018/09/24 @@ -75,30 +41,10 @@ public final class IBM037Encoder __c = '?'; // Map - __b[__o] = IBM037Encoder._MAP[__c]; + __b[__o] = IBM037Base._MAP[__c]; // Only single characters written return 1; } - - /** - * {@inheritDoc} - * @since 2018/10/13 - */ - @Override - public final String encodingName() - { - return "ibm037"; - } - - /** - * {@inheritDoc} - * @since 2018/12/08 - */ - @Override - public final int maximumSequenceLength() - { - return 1; - } } diff --git a/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/PrintStreamWriter.java b/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/PrintStreamWriter.java index d9e122457c..2c771d0ac9 100644 --- a/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/PrintStreamWriter.java +++ b/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/PrintStreamWriter.java @@ -122,6 +122,9 @@ public class PrintStreamWriter /** * {@inheritDoc} * @since 2016/08/12 + * @param __c + * @param __o + * @param __l */ @Override public void write(char[] __c, int __o, int __l) diff --git a/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/ShiftJisBase.java b/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/ShiftJisBase.java new file mode 100644 index 0000000000..3fccd47d20 --- /dev/null +++ b/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/ShiftJisBase.java @@ -0,0 +1,49 @@ +// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*- +// --------------------------------------------------------------------------- +// Multi-Phasic Applications: SquirrelJME +// Copyright (C) Stephanie Gawroriski +// --------------------------------------------------------------------------- +// SquirrelJME is under the GNU General Public License v3+, or later. +// See license.mkd for licensing and copyright information. +// --------------------------------------------------------------------------- + +package cc.squirreljme.runtime.cldc.io; + +/** + * Base for Shift-JIS. + * + * @since 2022/07/12 + */ +public abstract class ShiftJisBase + implements NamedCodec +{ + /** + * {@inheritDoc} + * @since 2021/06/13 + */ + @Override + public final double averageSequenceLength() + { + return 2.0D; + } + + /** + * {@inheritDoc} + * @since 2021/06/13 + */ + @Override + public final String encodingName() + { + return "shift-jis"; + } + + /** + * {@inheritDoc} + * @since 2021/06/13 + */ + @Override + public final int maximumSequenceLength() + { + return 2; + } +} diff --git a/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/ShiftJisDecoder.java b/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/ShiftJisDecoder.java index 073f2d7a87..1eee4c9943 100644 --- a/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/ShiftJisDecoder.java +++ b/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/ShiftJisDecoder.java @@ -21,6 +21,7 @@ import java.io.InputStream; * @since 2021/06/13 */ public class ShiftJisDecoder + extends ShiftJisBase implements Decoder { /** The loaded Shift-JIS table. */ @@ -31,16 +32,6 @@ public class ShiftJisDecoder * @since 2021/06/13 */ @Override - public double averageSequenceLength() - { - return 2.0D; - } - - /** - * {@inheritDoc} - * @since 2021/06/13 - */ - @Override public int decode(byte[] __b, int __o, int __l) throws IndexOutOfBoundsException, NullPointerException { @@ -70,7 +61,7 @@ public class ShiftJisDecoder // Single byte half-width Katakana else if (a >= 0xA1 && a <= 0xDF) - return this.__singleByteHalfWidthKatakana(a) | 0x1_0000; + return ShiftJisDecoder.__singleByteHalfWidthKatakana(a) | 0x1_0000; // Two byte characters else if ((a >= 0x81 && a <= 0x9F) || (a >= 0xE0 && a <= 0xEF)) @@ -89,26 +80,6 @@ public class ShiftJisDecoder } /** - * {@inheritDoc} - * @since 2021/06/13 - */ - @Override - public String encodingName() - { - return "shift-jis"; - } - - /** - * {@inheritDoc} - * @since 2021/06/13 - */ - @Override - public int maximumSequenceLength() - { - return 2; - } - - /** * Decodes a single byte half-width katakana character * * @param __a The byte. @@ -116,7 +87,7 @@ public class ShiftJisDecoder * @since 2022/02/14 */ @SuppressWarnings("MagicNumber") - private int __singleByteHalfWidthKatakana(int __a) + private static int __singleByteHalfWidthKatakana(int __a) { switch (__a) { diff --git a/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/ShiftJisEncoder.java b/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/ShiftJisEncoder.java new file mode 100644 index 0000000000..41cd7738bb --- /dev/null +++ b/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/io/ShiftJisEncoder.java @@ -0,0 +1,33 @@ +// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*- +// --------------------------------------------------------------------------- +// Multi-Phasic Applications: SquirrelJME +// Copyright (C) Stephanie Gawroriski +// --------------------------------------------------------------------------- +// SquirrelJME is under the GNU General Public License v3+, or later. +// See license.mkd for licensing and copyright information. +// --------------------------------------------------------------------------- + +package cc.squirreljme.runtime.cldc.io; + +import cc.squirreljme.runtime.cldc.debug.Debugging; + +/** + * Encoder for Shift-JIS. + * + * @since 2022/07/12 + */ +public class ShiftJisEncoder + extends ShiftJisBase + implements Encoder +{ + /** + * {@inheritDoc} + * @since 2022/07/12 + */ + @Override + public int encode(char __c, byte[] __b, int __o, int __l) + throws IndexOutOfBoundsException, NullPointerException + { + throw Debugging.todo(); + } +} diff --git a/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/util/EnumTypeMap.java b/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/util/EnumTypeMap.java index 3a1620bdb5..0a883bf419 100644 --- a/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/util/EnumTypeMap.java +++ b/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/util/EnumTypeMap.java @@ -68,6 +68,7 @@ public final class EnumTypeMap, V> /** * {@inheritDoc} * @since 2021/03/13 + * @param __key */ @SuppressWarnings("unchecked") @Override diff --git a/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/util/SortedTreeMap.java b/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/util/SortedTreeMap.java index 7928a84da2..f68f7ebdd6 100644 --- a/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/util/SortedTreeMap.java +++ b/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/util/SortedTreeMap.java @@ -166,6 +166,7 @@ public class SortedTreeMap /** * {@inheritDoc} * @since 2016/09/07 + * @param __k */ @Override public V get(Object __k) diff --git a/modules/cldc-compact/src/main/java/java/io/BufferedWriter.java b/modules/cldc-compact/src/main/java/java/io/BufferedWriter.java index 936798c58b..c123b02d68 100644 --- a/modules/cldc-compact/src/main/java/java/io/BufferedWriter.java +++ b/modules/cldc-compact/src/main/java/java/io/BufferedWriter.java @@ -141,6 +141,9 @@ public class BufferedWriter * * {@inheritDoc} * @since 2018/09/18 + * @param __b + * @param __o + * @param __l */ @Override public void write(char[] __b, int __o, int __l) @@ -154,6 +157,9 @@ public class BufferedWriter /** * {@inheritDoc} * @since 2018/09/18 + * @param __s + * @param __o + * @param __l */ @Override public void write(String __s, int __o, int __l) diff --git a/modules/cldc-compact/src/main/java/java/io/OutputStreamWriter.java b/modules/cldc-compact/src/main/java/java/io/OutputStreamWriter.java index 5ce4a20f44..3e46e56acf 100644 --- a/modules/cldc-compact/src/main/java/java/io/OutputStreamWriter.java +++ b/modules/cldc-compact/src/main/java/java/io/OutputStreamWriter.java @@ -10,71 +10,173 @@ package java.io; import cc.squirreljme.runtime.cldc.debug.Debugging; +import cc.squirreljme.runtime.cldc.io.CodecFactory; +import cc.squirreljme.runtime.cldc.io.Encoder; +/** + * This class maps character based output to a byte based output, encoding + * any written characters to the output. + * + * @since 2022/07/12 + */ public class OutputStreamWriter extends Writer { - public OutputStreamWriter(OutputStream __a, String __b) - throws UnsupportedEncodingException + /** The encoder used to encode bytes. */ + private final Encoder _encoder; + + /** The stream to write to. */ + private final OutputStream _out; + + /** The internal working buffer for the encoder. */ + private final byte[] _workBuf; + + /** + * Initializes the writer, using the default character set. + * + * @param __out The stream to write to. + * @throws NullPointerException On null arguments. + * @since 2022/07/12 + */ + public OutputStreamWriter(OutputStream __out) + throws NullPointerException + { + this(__out, CodecFactory.defaultEncoder()); + } + + /** + * Initializes the writer. + * + * @param __out The stream to write to. + * @param __charset The character set to use for encoding. + * @throws NullPointerException On null arguments. + * @throws UnsupportedEncodingException If the encoding is not supported. + * @since 2022/07/12 + */ + public OutputStreamWriter(OutputStream __out, String __charset) + throws NullPointerException, UnsupportedEncodingException { - if (false) - throw new UnsupportedEncodingException(); - throw Debugging.todo(); + this(__out, CodecFactory.encoder(__charset)); } - public OutputStreamWriter(OutputStream __a) + /** + * Initializes the writer, using the specified internal encoder. + * + * @param __out The stream to write to. + * @throws NullPointerException On null arguments. + * @since 2022/07/12 + */ + private OutputStreamWriter(OutputStream __out, Encoder __encoder) + throws NullPointerException { - throw Debugging.todo(); + if (__out == null || __encoder == null) + throw new NullPointerException("NARG"); + + this._out = __out; + this._encoder = __encoder; + this._workBuf = new byte[__encoder.maximumSequenceLength()]; } + /** + * {@inheritDoc} + * @since 2022/07/12 + */ @Override public void close() throws IOException { - if (false) - throw new IOException(); - throw Debugging.todo(); + // Forward + this._out.close(); } + /** + * {@inheritDoc} + * @since 2022/07/12 + */ @Override public void flush() throws IOException { - if (false) - throw new IOException(); - throw Debugging.todo(); + // Forward + this._out.flush(); } + /** + * Returns the name of the encoding. + * + * @return The encoding name. + * @since 2022/07/12 + */ public String getEncoding() { - throw Debugging.todo(); + return this._encoder.encodingName(); } + /** + * {@inheritDoc} + * @since 2022/07/12 + */ @Override - public void write(int __a) + public void write(int __c) throws IOException { - if (false) - throw new IOException(); - throw Debugging.todo(); + this.__write((char)__c); } + /** + * {@inheritDoc} + * @since 2022/07/12 + */ @Override - public void write(char[] __a, int __b, int __c) - throws IOException + public void write(char[] __c, int __o, int __l) + throws IndexOutOfBoundsException, IOException, NullPointerException { - if (false) - throw new IOException(); - throw Debugging.todo(); + if (__c == null) + throw new NullPointerException("NARG"); + if (__o < 0 || __l < 0 || (__o + __l) < 0 || + (__o + __l) > __c.length) + throw new IndexOutOfBoundsException("IOOB"); + + for (int i = 0; i < __l; i++) + this.__write(__c[__o + i]); } + /** + * {@inheritDoc} + * @since 2022/07/12 + */ @Override - public void write(String __a, int __b, int __c) + public void write(String __str, int __off, int __len) + throws IndexOutOfBoundsException, IOException, NullPointerException + { + if (__str == null) + throw new NullPointerException("NARG"); + if (__off < 0 || __len < 0 || (__off + __len) < 0 || + (__off + __len) > __str.length()) + throw new IndexOutOfBoundsException("IOOB"); + + for (int i = 0; i < __len; i++) + this.__write(__str.charAt(__off + i)); + } + + /** + * Writes the given character. + * + * @param __c The character to write. + * @throws IOException On write errors. + * @since 2022/07/12 + */ + private void __write(char __c) throws IOException { - if (false) - throw new IOException(); - throw Debugging.todo(); + byte[] workBuf = this._workBuf; + int len = this._encoder.encode(__c, workBuf, 0, workBuf.length); + + // Should never happen! + if (len < 0) + throw Debugging.oops(); + + this._out.write(workBuf, 0, len); } } diff --git a/modules/cldc-compact/src/main/java/java/io/Reader.java b/modules/cldc-compact/src/main/java/java/io/Reader.java index b3f9fa60c8..9b8667ec0d 100644 --- a/modules/cldc-compact/src/main/java/java/io/Reader.java +++ b/modules/cldc-compact/src/main/java/java/io/Reader.java @@ -11,6 +11,7 @@ package java.io; import cc.squirreljme.runtime.cldc.annotation.ImplementationNote; import cc.squirreljme.runtime.cldc.debug.Debugging; +import java.lang.ref.WeakReference; public abstract class Reader implements Closeable @@ -29,7 +30,7 @@ public abstract class Reader "because it refers to itself.") protected Reader() { - this.lock = null; + this.lock = new WeakReference<>(this); } /** @@ -48,10 +49,6 @@ public abstract class Reader this.lock = __l; } - @Override - public abstract void close() - throws IOException; - /** * Reads multiple characters. * diff --git a/modules/cldc-compact/src/main/java/java/io/Writer.java b/modules/cldc-compact/src/main/java/java/io/Writer.java index be55d91984..75f244baa9 100644 --- a/modules/cldc-compact/src/main/java/java/io/Writer.java +++ b/modules/cldc-compact/src/main/java/java/io/Writer.java @@ -9,90 +9,196 @@ package java.io; -import cc.squirreljme.runtime.cldc.debug.Debugging; +import cc.squirreljme.runtime.cldc.annotation.ImplementationNote; +import java.lang.ref.WeakReference; +/** + * This is a base class for outputs which write with characters instead + * of bytes. + * + * @since 2022/07/12 + */ public abstract class Writer implements Appendable, Closeable { + /** The object to lock onto for streams. */ + @ImplementationNote("This may cause a never-free.") protected Object lock; + /** + * Initializes the writer. + * + * @since 2022/07/12 + */ + @ImplementationNote("The lock should be initialized to this, however " + + "this would result in the reader itself never able to be freed " + + "because it refers to itself.") protected Writer() { - throw Debugging.todo(); + this.lock = new WeakReference<>(this); } - protected Writer(Object __a) + /** + * Initializes the writer. + * + * @param __lock The lock to use. + * @throws NullPointerException On null arguments. + * @since 2022/07/12 + */ + protected Writer(Object __lock) + throws NullPointerException { - throw Debugging.todo(); + if (__lock == null) + throw new NullPointerException("NARG"); + + this.lock = __lock; } - @Override - public abstract void close() - throws IOException; - + /** + * Flushes the output. + * + * @throws IOException If this could not be flushed. + * @since 2022/07/12 + */ public abstract void flush() throws IOException; - public abstract void write(char[] __a, int __b, int __c) - throws IOException; + /** + * Writes the specified characters to the output. + * + * @param __c The characters to write. + * @param __o The offset into the buffer. + * @param __l The number of characters to write. + * @throws IndexOutOfBoundsException If the offset and/or length are + * negative or exceeds the array bounds. + * @throws IOException On write errors. + * @throws NullPointerException On null arguments. + * @since 2022/07/12 + */ + public abstract void write(char[] __c, int __o, int __l) + throws IndexOutOfBoundsException, IOException, NullPointerException; + /** + * {@inheritDoc} + * @since 2022/07/12 + */ @Override - public Writer append(CharSequence __a) + public Writer append(CharSequence __c) throws IOException { - if (false) - throw new IOException(); - throw Debugging.todo(); + this.__write((__c == null ? "null" : __c), 0, + (__c == null ? 4 : __c.length())); + return this; } + /** + * {@inheritDoc} + * @since 2022/07/12 + */ @Override - public Writer append(CharSequence __a, int __b, int __c) + public Writer append(CharSequence __c, int __s, int __e) throws IOException { - if (false) - throw new IOException(); - throw Debugging.todo(); + this.__write((__c == null ? "null" : __c), __s, __e - __s); + return this; } + /** + * {@inheritDoc} + * @since 2022/07/12 + */ @Override - public Writer append(char __a) + public Writer append(char __c) throws IOException { - if (false) - throw new IOException(); - throw Debugging.todo(); + this.__write(__c); + return this; } - public void write(int __a) + /** + * {@inheritDoc} + * @since 2022/07/12 + */ + public void write(int __c) throws IOException { - if (false) - throw new IOException(); - throw Debugging.todo(); + this.__write((char)__c); } - public void write(char[] __a) + /** + * {@inheritDoc} + * @since 2022/07/12 + */ + public void write(char[] __c) throws IOException { - if (false) - throw new IOException(); - throw Debugging.todo(); + this.write(__c, 0, __c.length); } - public void write(String __a) + /** + * {@inheritDoc} + * @since 2022/07/12 + */ + public void write(String __str) throws IOException { - if (false) - throw new IOException(); - throw Debugging.todo(); + this.__write(__str, 0, __str.length()); + } + + /** + * {@inheritDoc} + * @since 2022/07/12 + */ + public void write(String __str, int __off, int __len) + throws IndexOutOfBoundsException, IOException, NullPointerException + { + this.__write(__str, __off, __len); } - public void write(String __a, int __b, int __c) + /** + * Writes a single character. + * + * @param __c The single character to write. + * @throws IOException On write errors. + * @since 2022/07/12 + */ + private void __write(char __c) throws IOException { - if (false) - throw new IOException(); - throw Debugging.todo(); + char[] single = new char[1]; + single[0] = (char)__c; + + this.write(single, 0, 1); + } + + /** + * Writes the character sequence to the output. + * + * @param __str The string to write. + * @param __off The offset into the string. + * @param __len The length of the string. + * @throws IndexOutOfBoundsException If the offset and/or length are + * negative or exceed the array bounds. + * @throws IOException On write errors. + * @throws NullPointerException On null arguments. + * @since 2022/07/12 + */ + private void __write(CharSequence __str, int __off, int __len) + throws IndexOutOfBoundsException, IOException, NullPointerException + { + if (__str == null) + throw new NullPointerException("NARG"); + if (__off < 0 || __len < 0 || (__off + __len) < 0 || + (__off + __len) > __str.length()) + throw new IndexOutOfBoundsException("IOOB"); + + // Read in characters + char[] buf = new char[__len]; + for (int i = 0; i < __len; i++) + buf[i] = __str.charAt(__off + i); + + // Forward all of it + this.write(buf, 0, buf.length); } } diff --git a/modules/cldc-compact/src/main/java/java/util/AbstractMap.java b/modules/cldc-compact/src/main/java/java/util/AbstractMap.java index 27bbbf8a10..2e740962fb 100644 --- a/modules/cldc-compact/src/main/java/java/util/AbstractMap.java +++ b/modules/cldc-compact/src/main/java/java/util/AbstractMap.java @@ -55,16 +55,40 @@ public abstract class AbstractMap throw Debugging.todo(); } + /** + * {@inheritDoc} + * @since 2022/07/12 + */ @Override - public boolean equals(Object __a) + public boolean equals(Object __o) { - throw Debugging.todo(); + // Quick? + if (this == __o) + return true; + + // Not another map? + if (!(__o instanceof Map)) + return false; + + // Compares on the entry set + return this.entrySet().equals(((Map)__o).entrySet()); } + /** + * {@inheritDoc} + * @since 2022/07/12 + * @param __key + */ @Override - public V get(Object __a) + public V get(Object __key) { - throw Debugging.todo(); + // Manual scan through to find it + for (Map.Entry e : this.entrySet()) + if (Objects.equals(e.getKey(), __key)) + return e.getValue(); + + // Not found + return null; } /** diff --git a/modules/cldc-compact/src/main/java/java/util/AbstractSet.java b/modules/cldc-compact/src/main/java/java/util/AbstractSet.java index cf5e45d337..64b4358f1f 100644 --- a/modules/cldc-compact/src/main/java/java/util/AbstractSet.java +++ b/modules/cldc-compact/src/main/java/java/util/AbstractSet.java @@ -47,7 +47,8 @@ public abstract class AbstractSet if (this.size() != o.size()) return false; - // Just check if this set contains everything in the other set + // Just check if this set contains everything in the other set, note + // that this only works if the sets are the same size return this.containsAll(o); } diff --git a/modules/cldc-compact/src/main/java/java/util/HashMap.java b/modules/cldc-compact/src/main/java/java/util/HashMap.java index 605abcd78d..b88e289c4a 100644 --- a/modules/cldc-compact/src/main/java/java/util/HashMap.java +++ b/modules/cldc-compact/src/main/java/java/util/HashMap.java @@ -178,6 +178,7 @@ public class HashMap /** * {@inheritDoc} * @since 2018/10/10 + * @param __k */ @Override public V get(Object __k) diff --git a/modules/cldc-compact/src/main/java/java/util/Hashtable.java b/modules/cldc-compact/src/main/java/java/util/Hashtable.java index 6321d26179..11461942f4 100644 --- a/modules/cldc-compact/src/main/java/java/util/Hashtable.java +++ b/modules/cldc-compact/src/main/java/java/util/Hashtable.java @@ -219,6 +219,7 @@ public class Hashtable * {@inheritDoc} * @throws NullPointerException If the requested key is null. * @since 2019/05/05 + * @param __k */ @Override public V get(Object __k) diff --git a/modules/cldc-compact/src/main/java/java/util/Map.java b/modules/cldc-compact/src/main/java/java/util/Map.java index b8557fef0c..1c9ce74e39 100644 --- a/modules/cldc-compact/src/main/java/java/util/Map.java +++ b/modules/cldc-compact/src/main/java/java/util/Map.java @@ -22,7 +22,14 @@ public interface Map @Override boolean equals(Object __a); - V get(Object __a); + /** + * Obtains the key from the given map. + * + * @param __key The key to get. + * @return The value of the given key or {@code null} if not found. + * @since 2022/07/12 + */ + V get(Object __key); @Override int hashCode(); diff --git a/modules/cldc-compact/src/main/java/java/util/WeakHashMap.java b/modules/cldc-compact/src/main/java/java/util/WeakHashMap.java index 7b090f4984..e6811aae93 100644 --- a/modules/cldc-compact/src/main/java/java/util/WeakHashMap.java +++ b/modules/cldc-compact/src/main/java/java/util/WeakHashMap.java @@ -131,7 +131,7 @@ public class WeakHashMap } @Override - public V get(Object __a) + public V get(Object __key) { throw Debugging.todo(); } diff --git a/modules/cldc-compact/src/test/java/io/TestXStreamRW.java b/modules/cldc-compact/src/test/java/io/TestXStreamRW.java new file mode 100644 index 0000000000..9dd8fe0b1c --- /dev/null +++ b/modules/cldc-compact/src/test/java/io/TestXStreamRW.java @@ -0,0 +1,80 @@ +// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*- +// --------------------------------------------------------------------------- +// Multi-Phasic Applications: SquirrelJME +// Copyright (C) Stephanie Gawroriski +// --------------------------------------------------------------------------- +// SquirrelJME is under the GNU General Public License v3+, or later. +// See license.mkd for licensing and copyright information. +// --------------------------------------------------------------------------- + +package io; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.Reader; +import java.io.Writer; +import net.multiphasicapps.tac.TestFunction; + +/** + * Tests that {@link OutputStreamWriter} can link right into + * {@link InputStreamReader}. + * + * @since 2022/07/12 + */ +public class TestXStreamRW + extends TestFunction +{ + /** The test message. */ + public static final String MESSAGE = + "Squirrels are adorable and cute! Wiewi\u00F3rki s\u0105 urocze i " + + "urocze! \u30EA\u30B9\u304C\u53EF\u611B\u304F\u3066\u304B\u308F" + + "\u3044\u3044\uFF01"; + + /** + * {@inheritDoc} + * @since 2022/07/12 + */ + @Override + public String test(String __charset) + throws IOException + { + // Encode message + byte[] raw; + try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Writer w = new OutputStreamWriter(baos, __charset)) + { + // Write it out + w.write(TestXStreamRW.MESSAGE); + w.flush(); + + // Get the raw bytes + raw = baos.toByteArray(); + } + + // Decode message + StringBuilder sb = new StringBuilder(); + try (Reader r = new InputStreamReader(new ByteArrayInputStream(raw), + __charset)) + { + for (;;) + { + int c = r.read(); + + // EOF? + if (c < 0) + break; + + sb.append((char)c); + } + } + + // Is the string the same? + String result = sb.toString(); + this.secondary("bytes", raw); + this.secondary("equals", TestXStreamRW.MESSAGE.equals(result)); + return result; + } +} diff --git a/modules/cldc-compact/src/test/resources/io/TestXStreamRW.in b/modules/cldc-compact/src/test/resources/io/TestXStreamRW.in new file mode 100644 index 0000000000..0c9e66e469 --- /dev/null +++ b/modules/cldc-compact/src/test/resources/io/TestXStreamRW.in @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +result: NoResult +thrown: NoExceptionThrown +multi-parameters: ascii utf-8 iso-8859-1 iso-8859-15 +disabled-multi-parameters: ibm037 shift-jis diff --git a/modules/cldc-compact/src/test/resources/io/TestXStreamRW@ascii.in b/modules/cldc-compact/src/test/resources/io/TestXStreamRW@ascii.in new file mode 100644 index 0000000000..1c150b82d6 --- /dev/null +++ b/modules/cldc-compact/src/test/resources/io/TestXStreamRW@ascii.in @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +result: string:Squirrels\_are\_adorable\_and\_cute!\_Wiewi?rki\_s?\_urocze\_i + \_urocze!\_???????????? +thrown: NoExceptionThrown +secondary-bytes: byte[75]:83,113,117,105,114,114,101,108,115,32,97,114,101,32, + 97,100,111,114,97,98,108,101,32,97,110,100,32,99,117,116,101,33,32,87,105, + 101,119,105,63,114,107,105,32,115,63,32,117,114,111,99,122,101,32,105,32,117, + 114,111,99,122,101,33,32,63,63,63,63,63,63,63,63,63,63,63,63 +secondary-equals: false + diff --git a/modules/cldc-compact/src/test/resources/io/TestXStreamRW@ibm037.in b/modules/cldc-compact/src/test/resources/io/TestXStreamRW@ibm037.in new file mode 100644 index 0000000000..173abcff12 --- /dev/null +++ b/modules/cldc-compact/src/test/resources/io/TestXStreamRW@ibm037.in @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +result: string:Squirrels\_are\_adorable\_and\_cute!\_Wiewi\@00f3rki\_s\Q\_ + urocze\_i\_urocze!\_\Q\Q\Q\Q\Q\Q\Q\Q\Q\Q\Q\Q +thrown: NoExceptionThrown +secondary-bytes: byte[75]:-30,-104,-92,-119,-103,-103,-123,-109,-94,64,-127, + -103,-123,64,-127,-124,-106,-103,-127,-126,-109,-123,64,-127,-107,-124,64, + -125,-92,-93,-123,90,64,-26,-119,-123,-90,-119,-50,-103,-110,-119,64,-94,63, + 64,-92,-103,-106,-125,-87,-123,64,-119,64,-92,-103,-106,-125,-87,-123,90,64, + 63,63,63,63,63,63,63,63,63,63,63,63 +secondary-equals: false diff --git a/modules/cldc-compact/src/test/resources/io/TestXStreamRW@iso-8859-1.in b/modules/cldc-compact/src/test/resources/io/TestXStreamRW@iso-8859-1.in new file mode 100644 index 0000000000..6a2800878b --- /dev/null +++ b/modules/cldc-compact/src/test/resources/io/TestXStreamRW@iso-8859-1.in @@ -0,0 +1,9 @@ +Manifest-Version: 1.0 +result: string:Squirrels\_are\_adorable\_and\_cute!\_Wiewi\@00f3rki\_s?\_uro + cze\_i\_urocze!\_???????????? +thrown: NoExceptionThrown +secondary-bytes: byte[75]:83,113,117,105,114,114,101,108,115,32,97,114,101,32, + 97,100,111,114,97,98,108,101,32,97,110,100,32,99,117,116,101,33,32,87,105, + 101,119,105,-13,114,107,105,32,115,63,32,117,114,111,99,122,101,32,105,32, + 117,114,111,99,122,101,33,32,63,63,63,63,63,63,63,63,63,63,63,63 +secondary-equals: false diff --git a/modules/cldc-compact/src/test/resources/io/TestXStreamRW@iso-8859-15.in b/modules/cldc-compact/src/test/resources/io/TestXStreamRW@iso-8859-15.in new file mode 100644 index 0000000000..ff11a480c4 --- /dev/null +++ b/modules/cldc-compact/src/test/resources/io/TestXStreamRW@iso-8859-15.in @@ -0,0 +1,9 @@ +Manifest-Version: 1.0 +result: string:Squirrels\_are\_adorable\_and\_cute!\_Wiewi\@00f3rki\_s?\_uro + cze\_i\_urocze!\_???????????? +thrown: NoExceptionThrown +secondary-bytes: byte[75]:83,113,117,105,114,114,101,108,115,32,97,114,101,32, + 97,100,111,114,97,98,108,101,32,97,110,100,32,99,117,116,101,33,32,87,105,101, + 119,105,-13,114,107,105,32,115,63,32,117,114,111,99,122,101,32,105,32,117, + 114,111,99,122,101,33,32,63,63,63,63,63,63,63,63,63,63,63,63 +secondary-equals: false diff --git a/modules/cldc-compact/src/test/resources/io/TestXStreamRW@shift-jis.in b/modules/cldc-compact/src/test/resources/io/TestXStreamRW@shift-jis.in new file mode 100644 index 0000000000..57f3529451 --- /dev/null +++ b/modules/cldc-compact/src/test/resources/io/TestXStreamRW@shift-jis.in @@ -0,0 +1,11 @@ +Manifest-Version: 1.0 +result: string:Squirrels\_are\_adorable\_and\_cute!\_Wiewi?rki\_s?\_urocze\_ + i\_urocze!\_\@30ea\@30b9\@304c\@53ef\@611b\@304f\@3066\@304b\@308f\@3044 + \@3044\@ff01 +thrown: NoExceptionThrown +secondary-bytes: byte[87]:83,113,117,105,114,114,101,108,115,32,97,114,101, + 32,97,100,111,114,97,98,108,101,32,97,110,100,32,99,117,116,101,33,32,87,105, + 101,119,105,63,114,107,105,32,115,63,32,117,114,111,99,122,101,32,105,32, + 117,114,111,99,122,101,33,32,-125,-118,-125,88,-126,-86,-119,-62,-120,-92, + -126,-83,-126,-60,-126,-87,-126,-19,-126,-94,-126,-94,-127,73 +secondary-equals: false diff --git a/modules/cldc-compact/src/test/resources/io/TestXStreamRW@utf-8.in b/modules/cldc-compact/src/test/resources/io/TestXStreamRW@utf-8.in new file mode 100644 index 0000000000..8f7e3f4318 --- /dev/null +++ b/modules/cldc-compact/src/test/resources/io/TestXStreamRW@utf-8.in @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +result: string:Squirrels\_are\_adorable\_and\_cute!\_Wiewi\@00f3rki\_s\@0105 + \_urocze\_i\_urocze!\_\@30ea\@30b9\@304c\@53ef\@611b\@304f\@3066\@304b + \@308f\@3044\@3044\@ff01 +thrown: NoExceptionThrown +secondary-bytes: byte[101]:83,113,117,105,114,114,101,108,115,32,97,114,101, + 32,97,100,111,114,97,98,108,101,32,97,110,100,32,99,117,116,101,33,32,87, + 105,101,119,105,-61,-77,114,107,105,32,115,-60,-123,32,117,114,111,99,122, + 101,32,105,32,117,114,111,99,122,101,33,32,-29,-125,-86,-29,-126,-71,-29, + -127,-116,-27,-113,-81,-26,-124,-101,-29,-127,-113,-29,-127,-90,-29,-127, + -117,-29,-126,-113,-29,-127,-124,-29,-127,-124,-17,-68,-127 +secondary-equals: true diff --git a/modules/collections/src/main/java/net/multiphasicapps/collections/EmptyMap.java b/modules/collections/src/main/java/net/multiphasicapps/collections/EmptyMap.java index 2f9c3d8f95..76f07f304e 100644 --- a/modules/collections/src/main/java/net/multiphasicapps/collections/EmptyMap.java +++ b/modules/collections/src/main/java/net/multiphasicapps/collections/EmptyMap.java @@ -69,6 +69,7 @@ public class EmptyMap /** * {@inheritDoc} * @since 2016/05/12 + * @param __k */ @Override public Object get(Object __k) diff --git a/modules/collections/src/main/java/net/multiphasicapps/collections/IdentityMap.java b/modules/collections/src/main/java/net/multiphasicapps/collections/IdentityMap.java index 6fb70dba06..aa3efb32de 100644 --- a/modules/collections/src/main/java/net/multiphasicapps/collections/IdentityMap.java +++ b/modules/collections/src/main/java/net/multiphasicapps/collections/IdentityMap.java @@ -76,6 +76,7 @@ public final class IdentityMap /** * {@inheritDoc} * @since 2021/11/28 + * @param __k */ @SuppressWarnings("unchecked") @Override diff --git a/modules/collections/src/main/java/net/multiphasicapps/collections/UnmodifiableMap.java b/modules/collections/src/main/java/net/multiphasicapps/collections/UnmodifiableMap.java index 265e73baef..0c91ee211b 100644 --- a/modules/collections/src/main/java/net/multiphasicapps/collections/UnmodifiableMap.java +++ b/modules/collections/src/main/java/net/multiphasicapps/collections/UnmodifiableMap.java @@ -97,6 +97,7 @@ public final class UnmodifiableMap /** * {@inheritDoc} * @since 2016/02/29 + * @param __k */ @Override public V get(Object __k) diff --git a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/__QuickTable__.java b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/__QuickTable__.java index 8a9b284c7d..5a1086967d 100644 --- a/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/__QuickTable__.java +++ b/modules/debug-jdwp/src/main/java/cc/squirreljme/jdwp/__QuickTable__.java @@ -91,6 +91,7 @@ final class __QuickTable__ /** * {@inheritDoc} * @since 2021/03/13 + * @param __key */ @Override public I get(Object __key) diff --git a/modules/json/src/main/java/net/multiphasicapps/jsr353/ImplMegaFactory.java b/modules/json/src/main/java/net/multiphasicapps/jsr353/ImplMegaFactory.java index fe86655db7..52db619f55 100644 --- a/modules/json/src/main/java/net/multiphasicapps/jsr353/ImplMegaFactory.java +++ b/modules/json/src/main/java/net/multiphasicapps/jsr353/ImplMegaFactory.java @@ -137,7 +137,7 @@ public class ImplMegaFactory if (__i == null) throw new NullPointerException("No input stream specified."); - // Return auto detection stream, sort of + // Return auto-detection stream, sort of return this.createReader(new UTFDetectISR(__i)); } diff --git a/modules/json/src/test/java/TestGenerateSameJson.java b/modules/json/src/test/java/TestGenerateSameJson.java new file mode 100644 index 0000000000..8041855406 --- /dev/null +++ b/modules/json/src/test/java/TestGenerateSameJson.java @@ -0,0 +1,65 @@ +// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*- +// --------------------------------------------------------------------------- +// Multi-Phasic Applications: SquirrelJME +// Copyright (C) Stephanie Gawroriski +// --------------------------------------------------------------------------- +// SquirrelJME is under the GNU General Public License v3+, or later. +// See license.mkd for licensing and copyright information. +// --------------------------------------------------------------------------- + +import com.oracle.json.JsonObject; +import com.oracle.json.spi.JsonProvider; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import net.multiphasicapps.tac.TestBoolean; + +/** + * Tests that the same JSON file is generated, that is the writer can write + * the JSON but then also parse the JSON it wrote. + * + * @since 2022/07/12 + */ +public class TestGenerateSameJson + extends TestBoolean +{ + /** + * {@inheritDoc} + * @since 2022/07/12 + */ + @Override + public boolean test() + throws Throwable + { + // Read initial object + JsonObject first; + try (InputStream in = TestJsonParse.class + .getResourceAsStream("sample.json")) + { + // Read in the object + first = JsonProvider.provider() + .createReader(in).readObject(); + } + + // Write byte array + byte[] rawData; + try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) + { + JsonProvider.provider().createWriter(baos).write(first); + + rawData = baos.toByteArray(); + } + + // Read second object + JsonObject second; + try (InputStream in = new ByteArrayInputStream(rawData)) + { + // Read in the object + second = JsonProvider.provider() + .createReader(in).readObject(); + } + + // These should be the same! + return first.equals(second); + } +} diff --git a/modules/json/src/test/java/TestJsonParse.java b/modules/json/src/test/java/TestJsonParse.java new file mode 100644 index 0000000000..7a548dbc12 --- /dev/null +++ b/modules/json/src/test/java/TestJsonParse.java @@ -0,0 +1,72 @@ +// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*- +// --------------------------------------------------------------------------- +// Multi-Phasic Applications: SquirrelJME +// Copyright (C) Stephanie Gawroriski +// --------------------------------------------------------------------------- +// SquirrelJME is under the GNU General Public License v3+, or later. +// See license.mkd for licensing and copyright information. +// --------------------------------------------------------------------------- + +import com.oracle.json.JsonArray; +import com.oracle.json.JsonObject; +import com.oracle.json.JsonValue; +import com.oracle.json.spi.JsonProvider; +import java.io.IOException; +import java.io.InputStream; +import net.multiphasicapps.tac.TestRunnable; + +/** + * Tests that JSON can be parsed properly. + * + * @since 2022/07/12 + */ +public class TestJsonParse + extends TestRunnable +{ + /** + * {@inheritDoc} + * + * @since 2022/07/12 + */ + @Override + public void test() + throws IOException + { + try (InputStream in = TestJsonParse.class + .getResourceAsStream("sample.json")) + { + // Read in the object + JsonObject obj = JsonProvider.provider() + .createReader(in).readObject(); + + this.secondary("string", obj.getString("string")); + this.secondary("false", obj.getBoolean("false")); + this.secondary("true", obj.getBoolean("true")); + this.secondary("int", obj.getInt("int")); + this.secondary("long", + obj.getJsonNumber("long").longValue()); + this.secondary("null", + obj.get("null") == JsonValue.NULL); + + // The array within + JsonArray array = obj.getJsonArray("array"); + + this.secondary("array-length", array.size()); + for (int i = 0, n = array.size(); i < n; i++) + this.secondary("array-" + i, + array.get(i).getValueType().toString()); + + // Sub object + JsonObject sub = obj.getJsonObject("object"); + + this.secondary("object-string", sub.getString("string")); + this.secondary("object-false", sub.getBoolean("false")); + this.secondary("object-true", sub.getBoolean("true")); + this.secondary("object-int", sub.getInt("int")); + this.secondary("object-long", + sub.getJsonNumber("long").longValue()); + this.secondary("object-null", + sub.get("null") == JsonValue.NULL); + } + } +} diff --git a/modules/json/src/test/resources/TestGenerateSameJson.in b/modules/json/src/test/resources/TestGenerateSameJson.in new file mode 100644 index 0000000000..a083549cb8 --- /dev/null +++ b/modules/json/src/test/resources/TestGenerateSameJson.in @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +result: true +thrown: NoExceptionThrown diff --git a/modules/json/src/test/resources/TestJsonParse.in b/modules/json/src/test/resources/TestJsonParse.in new file mode 100644 index 0000000000..51e0bd5a94 --- /dev/null +++ b/modules/json/src/test/resources/TestJsonParse.in @@ -0,0 +1,22 @@ +Manifest-Version: 1.0 +result: NoResult +thrown: NoExceptionThrown +secondary-string: string:string +secondary-false: false +secondary-true: true +secondary-int: int:1234 +secondary-long: long:123412341234 +secondary-null: true +secondary-array--length: int:6 +secondary-array--0: string:STRING +secondary-array--1: string:FALSE +secondary-array--2: string:TRUE +secondary-array--3: string:NUMBER +secondary-array--4: string:NUMBER +secondary-array--5: string:NULL +secondary-object--string: string:string +secondary-object--false: false +secondary-object--true: true +secondary-object--int: int:1234 +secondary-object--long: long:123412341234 +secondary-object--null: true diff --git a/modules/json/src/test/resources/sample.json b/modules/json/src/test/resources/sample.json new file mode 100644 index 0000000000..5dc4360490 --- /dev/null +++ b/modules/json/src/test/resources/sample.json @@ -0,0 +1,18 @@ +{ + "string": "string", + "false": false, + "true": true, + "int": 1234, + "long": 123412341234, + "null": null, + "array": ["string", false, true, 1234, 123412341234, null], + "object": { + "string": "string", + "false": false, + "true": true, + "int": 1234, + "long": 123412341234, + "null": null, + "array": ["string", false, true, 1234, 123412341234] + } +} -- 2.11.4.GIT