updated test cases for spring 2006 schema, and major debug of locking system
[vamsas.git] / src / org / vamsas / client / simpleclient / VamsasArchiveReader.java
index b4455ac..2df47f5 100644 (file)
@@ -35,8 +35,8 @@ public class VamsasArchiveReader {
   ZipInputStream jstream=null;
   Hashtable strmentries = null;
   private void streamInit() {
-    throw new Error("VamsasArchiveReader(Stream) Not implemented!");
-    /* if (!stream) {
+    //throw new Error("VamsasArchiveReader(Stream) Not implemented!");
+     if (!stream) {
       log.debug("Skipping init for Jar Stream input.");
       return;
     }
@@ -63,7 +63,7 @@ public class VamsasArchiveReader {
     catch (Exception e) {
       log.warn("Exceptions during init!",e);
       jstream=null;
-    }*/
+    }
   }
   
   public VamsasArchiveReader(File vamsasfile) {
@@ -87,12 +87,18 @@ public class VamsasArchiveReader {
    */
   public VamsasArchiveReader(Lock vamsaslock) {
     // LATER: implement or remove
-    throw new Error("VamsasArchiveReading from locked IO stream not yet implemented.");
-    //rfile = vamsaslock.rafile;
-    //stream = true;
-    //streamInit();
-    //if (jstream==null)
-    //  throw new Error("Failed to open archive from Locked random access stream.");
+    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)
+      throw new Error("Failed to open archive from Locked random access stream.");
   }
   
   /**
@@ -134,7 +140,7 @@ public class VamsasArchiveReader {
       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);