X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fserial%2FSerialUtils.java;h=480990a5be8dd2b06c43b44145822ac0dfdc81b0;hb=95c5b4f9f95b6b934622393d851fc7e67966a8c2;hp=b083e3461e2b63d3c6d2a6e702d8cf60ef5d32b0;hpb=4d31956549a05df6dca42d58a1150a348a58dcd1;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/serial/SerialUtils.java b/src/be/nikiroo/utils/serial/SerialUtils.java index b083e34..480990a 100644 --- a/src/be/nikiroo/utils/serial/SerialUtils.java +++ b/src/be/nikiroo/utils/serial/SerialUtils.java @@ -19,9 +19,9 @@ import java.util.UnknownFormatConversionException; import be.nikiroo.utils.IOUtils; import be.nikiroo.utils.Image; -import be.nikiroo.utils.NextableInputStream; -import be.nikiroo.utils.NextableInputStreamStep; import be.nikiroo.utils.StringUtils; +import be.nikiroo.utils.streams.NextableInputStream; +import be.nikiroo.utils.streams.NextableInputStreamStep; /** * Small class to help with serialisation. @@ -63,17 +63,19 @@ public class SerialUtils { @Override protected void toStream(OutputStream out, Object value) throws IOException { - // TODO: we use \n to separate, and b64 to un-\n -- but we could - // use \\n ? + + // TODO: we use \n to separate, and b64 to un-\n + // -- but we could use \\n ? String type = value.getClass().getCanonicalName(); type = type.substring(0, type.length() - 2); // remove the [] write(out, type); - write(out, "\r"); try { for (int i = 0; true; i++) { Object item = Array.get(value, i); + // encode it normally if direct value + write(out, "\r"); if (!SerialUtils.encode(out, item)) { try { // TODO: bad escaping? @@ -86,7 +88,6 @@ public class SerialUtils { .getMessage()); } } - write(out, "\r"); } } catch (ArrayIndexOutOfBoundsException e) { // Done. @@ -372,8 +373,9 @@ public class SerialUtils { e.printStackTrace(); // should not happen (see // setAccessible) } + + write(out, "\n}"); } - write(out, "\n}"); } /** @@ -403,9 +405,9 @@ public class SerialUtils { } else if (value.getClass().getSimpleName().endsWith("[]")) { // Simple name does support [] suffix and do not return NULL for // inner anonymous classes - return customTypes.get("[]").encode(out, value); + customTypes.get("[]").encode(out, value); } else if (customTypes.containsKey(value.getClass().getCanonicalName())) { - return customTypes.get(value.getClass().getCanonicalName())// + customTypes.get(value.getClass().getCanonicalName())// .encode(out, value); } else if (value instanceof String) { encodeString(out, (String) value); @@ -604,6 +606,7 @@ public class SerialUtils { // aa bb -> "aa\tbb" static void encodeString(OutputStream out, String raw) throws IOException { + // TODO: not. efficient. out.write('\"'); // TODO !! utf-8 required for (char car : raw.toCharArray()) {