updated test cases for spring 2006 schema, and major debug of locking system
[vamsas.git] / src / org / vamsas / client / simpleclient / VamsasArchiveReader.java
index d0476cd..2df47f5 100644 (file)
@@ -35,7 +35,8 @@ public class VamsasArchiveReader {
   ZipInputStream jstream=null;
   Hashtable strmentries = null;
   private void streamInit() {
-    if (!stream) {
+    //throw new Error("VamsasArchiveReader(Stream) Not implemented!");
+     if (!stream) {
       log.debug("Skipping init for Jar Stream input.");
       return;
     }
@@ -48,13 +49,13 @@ public class VamsasArchiveReader {
       if (jstream.available()==0)
         log.warn("Can't read from JarInputStream (Locked stream!)");
       ZipEntry entry=null;
+      long pos=0;
       do {
-        long pos = rfile.getFilePointer();
         if ((entry=jstream.getNextEntry())!=null) {
           if (strmentries.containsKey(entry.getName())) {
             log.info("Only recording last of duplicate entries '"+entry.getName()+"'");
           } 
-          strmentries.put(entry.getName(), new Long(pos));
+          strmentries.put(entry.getName(), new Long(pos++));
           jstream.closeEntry();
         }
       } while (entry!=null);
@@ -85,7 +86,15 @@ public class VamsasArchiveReader {
    * @param vamsaslock
    */
   public VamsasArchiveReader(Lock vamsaslock) {
-    rfile = vamsaslock.rafile;
+    // LATER: implement or remove
+    if (vamsaslock==null || !vamsaslock.isLocked())
+      throw new Error("IMPLEMENTATION ERROR: Cannot create a VamsasArchiveReader without a valid lock.");
+    // throw new Error("VamsasArchiveReading from locked IO stream not yet implemented.");
+    try {
+      rfile = vamsaslock.getRaFile();
+    } catch (Exception e) {
+      log.warn("Unexpected IO Exception when accessing locked vamsas archive stream "+vamsaslock.target,e);
+    }
     stream = true;
     streamInit();
     if (jstream==null)
@@ -124,12 +133,14 @@ public class VamsasArchiveReader {
       return null;
     }
     try {
-      jstream.reset();
+      jstream=null;
+      rfile.seek(0);
+      jstream = new ZipInputStream(new FileInputStream(rfile.getFD()));
       ZipEntry entry = null;
       long epos = entrypos.longValue();
       do {
         entry = jstream.getNextEntry();
-      } while (entry!=null && epos-->0);  
+      } while (entry!=null && --epos>=0);  
         // rfile.seek(entrypos.longValue());
       // make a Jar entry from a zip entry.
       return new JarEntry(entry);