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.
@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?
.getMessage());
}
}
- write(out, "\r");
}
} catch (ArrayIndexOutOfBoundsException e) {
// Done.
// setAccessible)
}
}
- write(out, "\n}");
}
/**
} 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);
// 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()) {