code cleanup + BufInputStream.is()
[nikiroo-utils.git] / src / be / nikiroo / utils / serial / Importer.java
index f7fece064d6028d8fca8ff5a742cf997f52f52b2..5b75d313bc465918feb18786f90badb163ece6be 100644 (file)
@@ -5,9 +5,11 @@ import java.io.InputStream;
 import java.lang.reflect.Field;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.zip.GZIPInputStream;
 
 import be.nikiroo.utils.IOUtils;
-import be.nikiroo.utils.StringUtils;
+import be.nikiroo.utils.streams.Base64InputStream;
+import be.nikiroo.utils.streams.BufferedInputStream;
 import be.nikiroo.utils.streams.NextableInputStream;
 import be.nikiroo.utils.streams.NextableInputStreamStep;
 
@@ -92,8 +94,13 @@ public class Importer {
 
                                if (zip || b64) {
                                        stream.skip("XXX:".length());
-                                       InputStream decoded = StringUtils.unbase64(stream.open(),
-                                                       zip);
+
+                                       InputStream decoded = stream.open();
+                                       if (zip) {
+                                               decoded = new GZIPInputStream(decoded);
+                                       }
+                                       decoded = new Base64InputStream(decoded, false);
+
                                        try {
                                                read(decoded);
                                        } finally {
@@ -130,7 +137,7 @@ public class Importer {
         * @throws IOException
         *             if the content cannot be read (for instance, corrupt data)
         */
-       private boolean processLine(InputStream in) throws NoSuchFieldException,
+       private boolean processLine(BufferedInputStream in) throws NoSuchFieldException,
                        NoSuchMethodException, ClassNotFoundException, IOException {
 
                // Defer to latest child if any
@@ -149,10 +156,6 @@ 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);