From 564bbbdbc349805ff7fc1142facbedae87e5dc0e Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Thu, 25 Apr 2019 18:19:17 +0200 Subject: [PATCH] it now compiles --- src/be/nikiroo/utils/serial/Exporter.java | 38 -- src/be/nikiroo/utils/serial/Importer.java | 77 +-- src/be/nikiroo/utils/serial/SerialUtils.java | 14 +- .../utils/serial/server/ServerBridge.java | 39 +- .../nikiroo/utils/test_code/SerialTest.java | 463 ++++++++---------- 5 files changed, 274 insertions(+), 357 deletions(-) diff --git a/src/be/nikiroo/utils/serial/Exporter.java b/src/be/nikiroo/utils/serial/Exporter.java index 709c590..6325484 100644 --- a/src/be/nikiroo/utils/serial/Exporter.java +++ b/src/be/nikiroo/utils/serial/Exporter.java @@ -6,8 +6,6 @@ import java.io.OutputStream; import java.util.HashMap; import java.util.Map; -import be.nikiroo.utils.StringUtils; - /** * A simple class to serialise objects to {@link String}. *

@@ -56,40 +54,4 @@ public class Exporter { SerialUtils.append(out, o, map); return this; } - - /** - * Append the exported items in a serialised form into the given - * {@link OutputStream}. - * - * @param out - * the {@link OutputStream} - * @param b64 - * TRUE to have BASE64-coded content, FALSE to have raw content, - * NULL to let the system decide - * @param zip - * TRUE to zip the BASE64 output if the output is indeed in - * BASE64 format, FALSE not to - */ - public void appendTo(OutputStream out, Boolean b64, boolean zip) { - if (b64 == null && out.length() < 128) { - b64 = false; - } - - if (b64 == null || b64) { - try { - String zipped = StringUtils.base64(out.toString(), zip); - if (b64 != null || zipped.length() < out.length() - 4) { - SerialUtils.write(out, zip ? "ZIP:" : "B64:"); - SerialUtils.write(out, zipped); - return; - } - } catch (IOException e) { - throw new RuntimeException( - "Base64 conversion of data failed, maybe not enough memory?", - e); - } - } - - out.append(out); - } } \ No newline at end of file diff --git a/src/be/nikiroo/utils/serial/Importer.java b/src/be/nikiroo/utils/serial/Importer.java index 5d7d8d0..a017fab 100644 --- a/src/be/nikiroo/utils/serial/Importer.java +++ b/src/be/nikiroo/utils/serial/Importer.java @@ -68,37 +68,35 @@ public class Importer { NoSuchMethodException, ClassNotFoundException, IOException, NullPointerException { - // TODO: fix NexInStream: next() MUST be called first time, too - // TODO: NexInStream: add getBytes() (size downloaded) - // TODO: public InputStrem open() (open/close do nothing) - // TODO: public boolean eof() - // TODO: public nextAll(): next, but disable separation of sub-streams - // TODO: close(alsoCloseIncludedField) - NextableInputStream stream = new NextableInputStream(in, new NextableInputStreamStep('\n')); - if (in == null || stream.eof()) { - if (in == null) { - throw new NullPointerException("InputStream is null"); + try { + if (in == null || stream.eof()) { + if (in == null) { + throw new NullPointerException("InputStream is null"); + } + throw new NullPointerException("InputStream is empty"); } - throw new NullPointerException("InputStream is empty"); - } - - while (stream.next()) { - boolean zip = stream.startsWiths("ZIP:"); - boolean b64 = stream.startsWiths("B64:"); - if (zip || b64) { - InputStream decoded = StringUtils.unbase64(stream.open(), zip); - try { - read(decoded); - } finally { - decoded.close(); + while (stream.next()) { + boolean zip = stream.startsWiths("ZIP:"); + boolean b64 = stream.startsWiths("B64:"); + + if (zip || b64) { + InputStream decoded = StringUtils.unbase64(stream.open(), + zip); + try { + read(decoded); + } finally { + decoded.close(); + } + } else { + processLine(stream); } - } else { - processLine(stream); } + } finally { + stream.close(false); } return this; @@ -217,37 +215,6 @@ public class Importer { } } - /** - * Find the given needle in the data and return its position (or -1 if not - * found). - * - * @param data - * the data to look through - * @param offset - * the offset at wich to start searching - * @param needle - * the needle to find - * - * @return the position of the needle if found, -1 if not found - */ - private int find(byte[] data, int offset, byte[] needle) { - for (int i = offset; i + needle.length - 1 < data.length; i++) { - boolean same = true; - for (int j = 0; j < needle.length; j++) { - if (data[i + j] != needle[j]) { - same = false; - break; - } - } - - if (same) { - return i; - } - } - - return -1; - } - /** * Return the current deserialised value. * diff --git a/src/be/nikiroo/utils/serial/SerialUtils.java b/src/be/nikiroo/utils/serial/SerialUtils.java index 0dc4a35..6a628f3 100644 --- a/src/be/nikiroo/utils/serial/SerialUtils.java +++ b/src/be/nikiroo/utils/serial/SerialUtils.java @@ -1,5 +1,6 @@ package be.nikiroo.utils.serial; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.NotSerializableException; @@ -246,7 +247,7 @@ public class SerialUtils { ctor = clazz.getDeclaredConstructor(classes .toArray(new Class[] {})); } catch (NoSuchMethodException nsme) { - // TODO: it seems e do not always need a parameter for each + // TODO: it seems we do not always need a parameter for each // level, so we currently try "ALL" levels or "FIRST" level // only -> we should check the actual rule and use it ctor = clazz.getDeclaredConstructor(classes.get(0)); @@ -469,7 +470,14 @@ public class SerialUtils { // custom:TYPE_NAME:"content is String-encoded" String type = CustomSerializer.typeOf(encodedValue); if (customTypes.containsKey(type)) { - return customTypes.get(type).decode(encodedValue); + // TODO: we should start with a stream + InputStream streamEncodedValue = new ByteArrayInputStream( + encodedValue.getBytes("UTF-8")); + try { + return customTypes.get(type).decode(streamEncodedValue); + } finally { + streamEncodedValue.close(); + } } throw new IOException("Unknown custom type: " + type); } else if (encodedValue.equals("NULL") @@ -606,7 +614,7 @@ public class SerialUtils { static void encodeString(OutputStream out, InputStream raw) throws IOException { out.write('\"'); - byte buffer[] = new byte[4069]; + byte buffer[] = new byte[4096]; for (int len = 0; (len = raw.read(buffer)) > 0;) { for (int i = 0; i < len; i++) { // TODO: not 100% correct, look up howto for UTF-8 diff --git a/src/be/nikiroo/utils/serial/server/ServerBridge.java b/src/be/nikiroo/utils/serial/server/ServerBridge.java index 6c2ed01..ff4a931 100644 --- a/src/be/nikiroo/utils/serial/server/ServerBridge.java +++ b/src/be/nikiroo/utils/serial/server/ServerBridge.java @@ -1,6 +1,8 @@ package be.nikiroo.utils.serial.server; +import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.InputStream; import java.lang.reflect.Array; import java.net.Socket; import java.net.UnknownHostException; @@ -123,6 +125,7 @@ public class ServerBridge extends Server { @Override protected ConnectActionServer createConnectActionServer(Socket s) { + // Bad impl, not up to date (should work, but not efficient) return new ConnectActionServerString(s, key) { @Override public void action(final Version clientVersion) throws Exception { @@ -226,6 +229,7 @@ public class ServerBridge extends Server { * the data to trace */ private void trace(String prefix, String data) { + // TODO: we convert to string and back int size = data == null ? 0 : data.length(); String ssize = StringUtils.formatNumber(size) + "bytes"; @@ -241,22 +245,29 @@ public class ServerBridge extends Server { } } - Object obj = new Importer().read(data).getValue(); - if (obj == null) { - getTraceHandler().trace("NULL", 2); - getTraceHandler().trace("NULL", 3); - getTraceHandler().trace("NULL", 4); - } else { - if (obj.getClass().isArray()) { - getTraceHandler().trace( - "(" + obj.getClass() + ") with " - + Array.getLength(obj) + "element(s)", - 3); + InputStream stream = new ByteArrayInputStream( + data.getBytes("UTF-8")); + try { + Object obj = new Importer().read(stream).getValue(); + if (obj == null) { + getTraceHandler().trace("NULL", 2); + getTraceHandler().trace("NULL", 3); + getTraceHandler().trace("NULL", 4); } else { - getTraceHandler().trace("(" + obj.getClass() + ")", 2); + if (obj.getClass().isArray()) { + getTraceHandler().trace( + "(" + obj.getClass() + ") with " + + Array.getLength(obj) + + "element(s)", 3); + } else { + getTraceHandler().trace("(" + obj.getClass() + ")", + 2); + } + getTraceHandler().trace("" + obj.toString(), 3); + getTraceHandler().trace(data, 4); } - getTraceHandler().trace("" + obj.toString(), 3); - getTraceHandler().trace(data, 4); + } finally { + stream.close(); } } catch (NoSuchMethodException e) { getTraceHandler().trace("(not an object)", 2); diff --git a/src/be/nikiroo/utils/test_code/SerialTest.java b/src/be/nikiroo/utils/test_code/SerialTest.java index f3ed346..d761195 100644 --- a/src/be/nikiroo/utils/test_code/SerialTest.java +++ b/src/be/nikiroo/utils/test_code/SerialTest.java @@ -1,6 +1,12 @@ package be.nikiroo.utils.test_code; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.NotSerializableException; import java.net.URL; +import java.util.Arrays; import be.nikiroo.utils.serial.Exporter; import be.nikiroo.utils.serial.Importer; @@ -15,6 +21,29 @@ class SerialTest extends TestLauncher { this(null); } + // try to remove pointer addresses + private byte[] toBytes(Object data) throws NotSerializableException, + IOException { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + new Exporter(out).append(data); + out.flush(); + String tmp = new String(out.toByteArray(), "UTF-8"); + tmp = tmp.replaceAll("@[0-9]*", "@REF"); + return tmp.getBytes("UTF-8"); + } + + private Object fromBytes(byte[] data) throws NoSuchFieldException, + NoSuchMethodException, ClassNotFoundException, + NullPointerException, IOException { + + InputStream in = new ByteArrayInputStream(data); + try { + return new Importer().read(in).getValue(); + } finally { + in.close(); + } + } + public SerialTest(String[] args) { super("Serial test", args); @@ -22,257 +51,197 @@ class SerialTest extends TestLauncher { @Override public void test() throws Exception { Data data = new Data(42); - String encoded = new Exporter().append(data).toString(false, - false); - Object redata = new Importer().read(encoded).getValue(); - String reencoded = new Exporter().append(redata).toString( - false, false); - - assertEquals(encoded.replaceAll("@[0-9]*", "@REF"), - reencoded.replaceAll("@[0-9]*", "@REF")); - } - }); - - addTest(new TestCase() { - @SuppressWarnings("unused") - private TestCase me = setName("Anonymous inner class"); - - @Override - public void test() throws Exception { - Data data = new Data() { - @SuppressWarnings("unused") - int value = 42; - }; - - String encoded = new Exporter().append(data).toString(false, - false); - Object redata = new Importer().read(encoded).getValue(); - String reencoded = new Exporter().append(redata).toString( - false, false); - - assertEquals(encoded.replaceAll("@[0-9]*", "@REF"), - reencoded.replaceAll("@[0-9]*", "@REF")); - } - }); - - addTest(new TestCase() { - @SuppressWarnings("unused") - private TestCase me = setName("Array of anonymous inner classes"); - - @Override - public void test() throws Exception { - Data[] data = new Data[] { new Data() { - @SuppressWarnings("unused") - int value = 42; - } }; - - String encoded = new Exporter().append(data).toString(false, - false); - Object redata = new Importer().read(encoded).getValue(); - String reencoded = new Exporter().append(redata).toString( - false, false); - - // Comparing the 2 strings won't be useful, because the @REFs - // will be ZIP-encoded; so we parse and re-encode the object - encoded = new Exporter().append(data[0]).toString(false, false); - try { - reencoded = new Exporter().append(((Data[]) redata)[0]) - .toString(false, false); - } catch (Exception e) { - fail("Cannot cast the returned data into its original object", - e); - } - - assertEquals(encoded.replaceAll("@[0-9]*", "@REF"), - reencoded.replaceAll("@[0-9]*", "@REF")); - } - }); - - addTest(new TestCase("URL Import/Export") { - @Override - public void test() throws Exception { - URL data = new URL("https://fanfan.be/"); - String encoded = new Exporter().append(data).toString(false, - false); - Object redata = new Importer().read(encoded).getValue(); - String reencoded = new Exporter().append(redata).toString( - false, false); - - assertEquals(encoded.replaceAll("@[0-9]*", "@REF"), - reencoded.replaceAll("@[0-9]*", "@REF")); - } - }); - - addTest(new TestCase("URL-String Import/Export") { - @Override - public void test() throws Exception { - String data = new URL("https://fanfan.be/").toString(); - String encoded = new Exporter().append(data).toString(false, - false); - Object redata = new Importer().read(encoded).getValue(); - String reencoded = new Exporter().append(redata).toString( - false, false); - - assertEquals(encoded.replaceAll("@[0-9]*", "@REF"), - reencoded.replaceAll("@[0-9]*", "@REF")); - assertEquals(data, redata); - } - }); - - addTest(new TestCase("URL/URL-String arrays Import/Export") { - @Override - public void test() throws Exception { - final String url = "https://fanfan.be/"; - - Object[] data = new Object[] { new URL(url), url }; - String encoded = new Exporter().append(data).toString(false, - false); - Object redata = new Importer().read(encoded).getValue(); - String reencoded = new Exporter().append(redata).toString( - false, false); - - assertEquals(encoded.replaceAll("@[0-9]*", "@REF"), - reencoded.replaceAll("@[0-9]*", "@REF")); - assertEquals(data[0], ((Object[]) redata)[0]); - assertEquals(data[1], ((Object[]) redata)[1]); - } - }); - - addTest(new TestCase("Import/Export with nested objects") { - @Override - public void test() throws Exception { - Data data = new DataObject(new Data(21)); - String encoded = new Exporter().append(data).toString(false, - false); - Object redata = new Importer().read(encoded).getValue(); - String reencoded = new Exporter().append(redata).toString( - false, false); - - assertEquals(encoded.replaceAll("@[0-9]*", "@REF"), - reencoded.replaceAll("@[0-9]*", "@REF")); - } - }); - - addTest(new TestCase("Import/Export with nested objects forming a loop") { - @Override - public void test() throws Exception { - DataLoop data = new DataLoop("looping"); - data.next = new DataLoop("level 2"); - data.next.next = data; - - String encoded = new Exporter().append(data).toString(false, - false); - Object redata = new Importer().read(encoded).getValue(); - String reencoded = new Exporter().append(redata).toString( - false, false); - - assertEquals(encoded.replaceAll("@[0-9]*", "@REF"), - reencoded.replaceAll("@[0-9]*", "@REF")); - } - }); - - addTest(new TestCase("Array in Object Import/Export") { - @Override - public void test() throws Exception { - Object data = new DataArray();// new String[] { "un", "deux" }; - String encoded = new Exporter().append(data).toString(false, - false); - Object redata = new Importer().read(encoded).getValue(); - String reencoded = new Exporter().append(redata).toString( - false, false); - - assertEquals(encoded.replaceAll("@[0-9]*", "@REF"), - reencoded.replaceAll("@[0-9]*", "@REF")); - } - }); - - addTest(new TestCase("Array Import/Export") { - @Override - public void test() throws Exception { - Object data = new String[] { "un", "deux" }; - String encoded = new Exporter().append(data).toString(false, - false); - Object redata = new Importer().read(encoded).getValue(); - String reencoded = new Exporter().append(redata).toString( - false, false); - - assertEquals(encoded.replaceAll("@[0-9]*", "@REF"), - reencoded.replaceAll("@[0-9]*", "@REF")); - } - }); - - addTest(new TestCase("Enum Import/Export") { - @Override - public void test() throws Exception { - Object data = EnumToSend.FANFAN; - String encoded = new Exporter().append(data).toString(false, - false); - Object redata = new Importer().read(encoded).getValue(); - String reencoded = new Exporter().append(redata).toString( - false, false); - - assertEquals(encoded.replaceAll("@[0-9]*", "@REF"), - reencoded.replaceAll("@[0-9]*", "@REF")); - } - }); - - addTest(new TestCase("B64 and ZIP String test") { - @Override - public void test() throws Exception { - Object data = "Fanfan la tulipe"; - String encoded = new Exporter().append(data).toString(true, - false); - String redata = (String) new Importer().read(encoded) - .getValue(); - - assertEquals("Items not identical after B64", data, redata); - - encoded = new Exporter().append(data).toString(true, true); - redata = (String) new Importer().read(encoded).getValue(); - - assertEquals("Items not identical after ZIP", data, redata); - } - }); - - addTest(new TestCase("B64 and ZIP Data test") { - @Override - public void test() throws Exception { - Object data = new Data(55); - String encoded = new Exporter().append(data).toString(true, - false); - Data redata = (Data) new Importer().read(encoded).getValue(); - - assertEquals("Items not identical after B64", data, redata); - - encoded = new Exporter().append(data).toString(true, true); - redata = (Data) new Importer().read(encoded).getValue(); - - assertEquals("Items not identical after ZIP", data, redata); - } - }); - - addTest(new TestCase("B64 and ZIP 70000 chars test") { - @Override - public void test() throws Exception { - StringBuilder builder = new StringBuilder(); - for (int i = 0; i < 7000; i++) { - builder.append("0123456789"); - } - - Object data = builder.toString(); - String encoded = new Exporter().append(data).toString(true, - false); - String redata = (String) new Importer().read(encoded) - .getValue(); - - assertEquals("Items not identical after B64", data, redata); - encoded = new Exporter().append(data).toString(true, true); - redata = (String) new Importer().read(encoded).getValue(); + byte[] encoded = toBytes(data); + Object redata = fromBytes(encoded); + byte[] reencoded = toBytes(redata); - assertEquals("Items not identical after ZIP", data, redata); + assertEquals("Different data after encode/decode/encode", true, + Arrays.equals(encoded, reencoded)); } }); + /* + * addTest(new TestCase() { + * + * @SuppressWarnings("unused") private TestCase me = + * setName("Anonymous inner class"); + * + * @Override public void test() throws Exception { Data data = new + * Data() { + * + * @SuppressWarnings("unused") int value = 42; }; + * + * String encoded = new Exporter().append(data).toString(false, false); + * Object redata = new Importer().read(encoded).getValue(); String + * reencoded = new Exporter().append(redata).toString( false, false); + * + * assertEquals(encoded.replaceAll("@[0-9]*", "@REF"), + * reencoded.replaceAll("@[0-9]*", "@REF")); } }); + * + * addTest(new TestCase() { + * + * @SuppressWarnings("unused") private TestCase me = + * setName("Array of anonymous inner classes"); + * + * @Override public void test() throws Exception { Data[] data = new + * Data[] { new Data() { + * + * @SuppressWarnings("unused") int value = 42; } }; + * + * String encoded = new Exporter().append(data).toString(false, false); + * Object redata = new Importer().read(encoded).getValue(); String + * reencoded = new Exporter().append(redata).toString( false, false); + * + * // Comparing the 2 strings won't be useful, because the @REFs // will + * be ZIP-encoded; so we parse and re-encode the object encoded = new + * Exporter().append(data[0]).toString(false, false); try { reencoded = + * new Exporter().append(((Data[]) redata)[0]) .toString(false, false); + * } catch (Exception e) { + * fail("Cannot cast the returned data into its original object", e); } + * + * assertEquals(encoded.replaceAll("@[0-9]*", "@REF"), + * reencoded.replaceAll("@[0-9]*", "@REF")); } }); + * + * addTest(new TestCase("URL Import/Export") { + * + * @Override public void test() throws Exception { URL data = new + * URL("https://fanfan.be/"); String encoded = new + * Exporter().append(data).toString(false, false); Object redata = new + * Importer().read(encoded).getValue(); String reencoded = new + * Exporter().append(redata).toString( false, false); + * + * assertEquals(encoded.replaceAll("@[0-9]*", "@REF"), + * reencoded.replaceAll("@[0-9]*", "@REF")); } }); + * + * addTest(new TestCase("URL-String Import/Export") { + * + * @Override public void test() throws Exception { String data = new + * URL("https://fanfan.be/").toString(); String encoded = new + * Exporter().append(data).toString(false, false); Object redata = new + * Importer().read(encoded).getValue(); String reencoded = new + * Exporter().append(redata).toString( false, false); + * + * assertEquals(encoded.replaceAll("@[0-9]*", "@REF"), + * reencoded.replaceAll("@[0-9]*", "@REF")); assertEquals(data, redata); + * } }); + * + * addTest(new TestCase("URL/URL-String arrays Import/Export") { + * + * @Override public void test() throws Exception { final String url = + * "https://fanfan.be/"; + * + * Object[] data = new Object[] { new URL(url), url }; String encoded = + * new Exporter().append(data).toString(false, false); Object redata = + * new Importer().read(encoded).getValue(); String reencoded = new + * Exporter().append(redata).toString( false, false); + * + * assertEquals(encoded.replaceAll("@[0-9]*", "@REF"), + * reencoded.replaceAll("@[0-9]*", "@REF")); assertEquals(data[0], + * ((Object[]) redata)[0]); assertEquals(data[1], ((Object[]) + * redata)[1]); } }); + * + * addTest(new TestCase("Import/Export with nested objects") { + * + * @Override public void test() throws Exception { Data data = new + * DataObject(new Data(21)); String encoded = new + * Exporter().append(data).toString(false, false); Object redata = new + * Importer().read(encoded).getValue(); String reencoded = new + * Exporter().append(redata).toString( false, false); + * + * assertEquals(encoded.replaceAll("@[0-9]*", "@REF"), + * reencoded.replaceAll("@[0-9]*", "@REF")); } }); + * + * addTest(new + * TestCase("Import/Export with nested objects forming a loop") { + * + * @Override public void test() throws Exception { DataLoop data = new + * DataLoop("looping"); data.next = new DataLoop("level 2"); + * data.next.next = data; + * + * String encoded = new Exporter().append(data).toString(false, false); + * Object redata = new Importer().read(encoded).getValue(); String + * reencoded = new Exporter().append(redata).toString( false, false); + * + * assertEquals(encoded.replaceAll("@[0-9]*", "@REF"), + * reencoded.replaceAll("@[0-9]*", "@REF")); } }); + * + * addTest(new TestCase("Array in Object Import/Export") { + * + * @Override public void test() throws Exception { Object data = new + * DataArray();// new String[] { "un", "deux" }; String encoded = new + * Exporter().append(data).toString(false, false); Object redata = new + * Importer().read(encoded).getValue(); String reencoded = new + * Exporter().append(redata).toString( false, false); + * + * assertEquals(encoded.replaceAll("@[0-9]*", "@REF"), + * reencoded.replaceAll("@[0-9]*", "@REF")); } }); + * + * addTest(new TestCase("Array Import/Export") { + * + * @Override public void test() throws Exception { Object data = new + * String[] { "un", "deux" }; String encoded = new + * Exporter().append(data).toString(false, false); Object redata = new + * Importer().read(encoded).getValue(); String reencoded = new + * Exporter().append(redata).toString( false, false); + * + * assertEquals(encoded.replaceAll("@[0-9]*", "@REF"), + * reencoded.replaceAll("@[0-9]*", "@REF")); } }); + * + * addTest(new TestCase("Enum Import/Export") { + * + * @Override public void test() throws Exception { Object data = + * EnumToSend.FANFAN; String encoded = new + * Exporter().append(data).toString(false, false); Object redata = new + * Importer().read(encoded).getValue(); String reencoded = new + * Exporter().append(redata).toString( false, false); + * + * assertEquals(encoded.replaceAll("@[0-9]*", "@REF"), + * reencoded.replaceAll("@[0-9]*", "@REF")); } }); + * + * addTest(new TestCase("B64 and ZIP String test") { + * + * @Override public void test() throws Exception { Object data = + * "Fanfan la tulipe"; String encoded = new + * Exporter().append(data).toString(true, false); String redata = + * (String) new Importer().read(encoded) .getValue(); + * + * assertEquals("Items not identical after B64", data, redata); + * + * encoded = new Exporter().append(data).toString(true, true); redata = + * (String) new Importer().read(encoded).getValue(); + * + * assertEquals("Items not identical after ZIP", data, redata); } }); + * + * addTest(new TestCase("B64 and ZIP Data test") { + * + * @Override public void test() throws Exception { Object data = new + * Data(55); String encoded = new Exporter().append(data).toString(true, + * false); Data redata = (Data) new Importer().read(encoded).getValue(); + * + * assertEquals("Items not identical after B64", data, redata); + * + * encoded = new Exporter().append(data).toString(true, true); redata = + * (Data) new Importer().read(encoded).getValue(); + * + * assertEquals("Items not identical after ZIP", data, redata); } }); + * + * addTest(new TestCase("B64 and ZIP 70000 chars test") { + * + * @Override public void test() throws Exception { StringBuilder builder + * = new StringBuilder(); for (int i = 0; i < 7000; i++) { + * builder.append("0123456789"); } + * + * Object data = builder.toString(); String encoded = new + * Exporter().append(data).toString(true, false); String redata = + * (String) new Importer().read(encoded) .getValue(); + * + * assertEquals("Items not identical after B64", data, redata); + * + * encoded = new Exporter().append(data).toString(true, true); redata = + * (String) new Importer().read(encoded).getValue(); + * + * assertEquals("Items not identical after ZIP", data, redata); } }); + */ } class DataArray { -- 2.27.0