working
[nikiroo-utils.git] / src / be / nikiroo / utils / serial / Importer.java
index eec30b24b754b248c9ebf55af950cefa1d4c97cf..f7fece064d6028d8fca8ff5a742cf997f52f52b2 100644 (file)
@@ -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:");
 
@@ -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);