developing streamReader tests.
authorjprocter <jprocter@compbio.dundee.ac.uk>
Fri, 24 Mar 2006 10:21:36 +0000 (10:21 +0000)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Fri, 24 Mar 2006 10:21:36 +0000 (10:21 +0000)
git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@206 be28352e-c001-0410-b1a7-c7978e42abec

src/org/vamsas/client/simpleclient/VamsasArchive.java
src/org/vamsas/client/simpleclient/VamsasArchiveReader.java
src/org/vamsas/test/simpleclient/ArchiveStreamReader.java [new file with mode: 0644]

index 4c4fbfd..6e8138b 100644 (file)
@@ -256,7 +256,7 @@ public class VamsasArchive {
         odoclock = new SessionFile(original);
       odoclock.lockFile();
       if (odoc == null) 
-        odoc = new VamsasArchiveReader(original);
+        odoc = new VamsasArchiveReader(odoclock.fileLock);
     }
   }
   
index 3d4fbe6..d0476cd 100644 (file)
@@ -124,10 +124,15 @@ public class VamsasArchiveReader {
       return null;
     }
     try {
-      rfile.seek(entrypos.longValue());
+      jstream.reset();
+      ZipEntry entry = null;
+      long epos = entrypos.longValue();
+      do {
+        entry = jstream.getNextEntry();
+      } while (entry!=null && epos-->0);  
+        // rfile.seek(entrypos.longValue());
       // make a Jar entry from a zip entry.
-      
-      return new JarEntry(jstream.getNextEntry());
+      return new JarEntry(entry);
     }
     catch (Exception e) {
       log.warn("Whilst seeking for "+entryname, e);
diff --git a/src/org/vamsas/test/simpleclient/ArchiveStreamReader.java b/src/org/vamsas/test/simpleclient/ArchiveStreamReader.java
new file mode 100644 (file)
index 0000000..1415731
--- /dev/null
@@ -0,0 +1,52 @@
+package org.vamsas.test.simpleclient;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import org.vamsas.client.simpleclient.SessionFile;
+import org.vamsas.client.simpleclient.VamsasArchiveReader;
+import org.vamsas.client.simpleclient.VamsasFile;
+import org.vamsas.objects.core.VAMSAS;
+import org.vamsas.objects.core.VamsasDocument;
+
+public class ArchiveStreamReader {
+  /**
+   * tests VamsasArchiveReader archive reader on a vamsas jar file opened as a stream
+   * @param args
+   */
+  public static void main(String args[]) {
+    
+    try {
+      VamsasFile av = new VamsasFile(new File(args[0]));
+      VamsasArchiveReader var = new VamsasArchiveReader(av.getLock());
+      VAMSAS roots[]=null;
+      if (var.isValid()) {
+        InputStreamReader vdoc = new InputStreamReader(var.getVamsasDocumentStream());
+        VamsasDocument doc = VamsasDocument.unmarshal(vdoc);
+        if (ArchiveReports.reportDocument(doc, var, true, System.out)) {
+          roots = doc.getVAMSAS();
+        }
+      } else {
+        InputStream vxmlis = var.getVamsasXmlStream();
+        
+        if (vxmlis!=null) { // Might be an old vamsas file.
+          BufferedInputStream ixml = new BufferedInputStream(var.getVamsasXmlStream());
+          InputStreamReader vxml = new InputStreamReader(ixml);
+          VAMSAS root;
+          // unmarshal seems to always close the stream (should check this)
+          if ((root = VAMSAS.unmarshal(vxml))!=null) {
+            System.out.println("Read a root.");
+            roots = new VAMSAS[1];
+            roots[0] = root;
+          }
+        }
+      }
+      if (!ArchiveReports.rootReport(roots, true, System.out))
+        System.err.print(args[0]+" is not a valid vamsas archive.");
+    } catch (Exception e) {
+      e.printStackTrace(System.err);
+    }
+  }
+}