Commits

Miki Tebeka committed 149c5f2

Multi file support - the start

Comments (0)

Files changed (1)

src/main/java/com/mikitebeka/mapred/ZipLineIterator.java

 public class ZipLineIterator implements Iterator<String> {
 
     private ZipInputStream zin = null;
-    private String name;
+    private String name = null;
+    private String nextLine = null;
+    private BufferedReader reader = null;
     private int pos = 0;
-    private long size;
-    private String nextLine;
-    private BufferedReader reader;
 
     public ZipLineIterator(InputStream in) throws IOException {
         zin = new ZipInputStream(in);
-        ZipEntry entry = zin.getNextEntry();
+
+        nextEntry();
+    }
+
+    private void nextEntry() {
+        nextLine = null;
+
+        if (entry != null) {
+            zin.closeEntry();
+        }
+
+        entry = zin.getNextEntry();
         if (entry == null) {
             return;
         }
 
-        size = entry.getSize();
         name = entry.getName();
         reader = new BufferedReader(new InputStreamReader(zin));
-
         nextLine = reader.readLine();
     }
 
     @Override
     public String next() {
         String line = nextLine;
+        pos += line.length();
+
         try {
             nextLine = reader.readLine();
         } catch (IOException e) {
-            nextLine = null;
+            nextEntry();
         }
 
         return line;
     }
 
     public float getProgress() {
-        if (size == 0) {
-            return 1.0f;
-        }
-
-        return (float) (((double) pos) / size);
+        // FIXME
+        return 0.5f;
     }
 
     /**