X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fserial%2FImporter.java;h=f7fece064d6028d8fca8ff5a742cf997f52f52b2;hb=23742ceddbd2de2d81d3bf86520e066b835dae5d;hp=a017fabfd362ea3ad27f72e0a6305856db2e41a1;hpb=564bbbdbc349805ff7fc1142facbedae87e5dc0e;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/serial/Importer.java b/src/be/nikiroo/utils/serial/Importer.java index a017fab..f7fece0 100644 --- a/src/be/nikiroo/utils/serial/Importer.java +++ b/src/be/nikiroo/utils/serial/Importer.java @@ -7,9 +7,9 @@ import java.util.HashMap; import java.util.Map; import be.nikiroo.utils.IOUtils; -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; /** * A simple class that can accept the output of {@link Exporter} to recreate @@ -46,7 +46,7 @@ public class Importer { * content, or a number of lines of it (any given line MUST be * complete though) and accumulate it with the already present data. * - * @param data + * @param in * the data to parse * * @return itself so it can be chained @@ -72,18 +72,26 @@ public class Importer { new NextableInputStreamStep('\n')); try { - if (in == null || stream.eof()) { - if (in == null) { - throw new NullPointerException("InputStream is null"); - } - throw new NullPointerException("InputStream is empty"); + if (in == null) { + throw new NullPointerException("InputStream is null"); } + boolean first = true; while (stream.next()) { + if (stream.eof()) { + if (first) { + throw new NullPointerException( + "InputStream empty, normal termination"); + } + return this; + } + first = false; + boolean zip = stream.startsWiths("ZIP:"); boolean b64 = stream.startsWiths("B64:"); if (zip || b64) { + stream.skip("XXX:".length()); InputStream decoded = StringUtils.unbase64(stream.open(), zip); try { @@ -106,7 +114,7 @@ public class Importer { * Read a single (whole) line of serialised data into this {@link Importer} * and accumulate it with the already present data. * - * @param line + * @param in * the line to parse * * @return TRUE if we are just done with one object or sub-object @@ -141,6 +149,10 @@ public class Importer { // TODO use the stream, Luke String line = IOUtils.readSmallStream(in); + if (line.isEmpty()) { + return false; + } + if (line.equals("{")) { // START: new child if needed if (link != null) { child = new Importer(map);