X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fserial%2FImporter.java;h=810d694db5a316a4aca1290b5b31650312005f0d;hb=23cf894daa02843da6e6f1b199eaaea29a739f81;hp=ad2d284904790214b2360fbee0bb35cbae66f29e;hpb=52fb9a5603f4842bba748fdbc8422e1906a42d41;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/serial/Importer.java b/src/be/nikiroo/utils/serial/Importer.java index ad2d284..810d694 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.StringUtils; import be.nikiroo.utils.streams.NextableInputStream; import be.nikiroo.utils.streams.NextableInputStreamStep; -import be.nikiroo.utils.StringUtils; /** * 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 @@ -75,11 +75,18 @@ public class Importer { if (in == null) { throw new NullPointerException("InputStream is null"); } - if (stream.eof()) { - throw new NullPointerException("InputStream is empty"); - } + 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:"); @@ -107,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 @@ -142,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); @@ -160,7 +171,12 @@ public class Importer { } else { if (line.endsWith(":")) { // construct - me = SerialUtils.createObject(type); + try { + me = SerialUtils.createObject(type); + } catch (NoSuchMethodException e) { + System.out.println("LINE: <" + line + ">"); + throw e; + } } else { // direct value int pos = line.indexOf(":");