From eb43261243af32f5fa483ed68f37b0fd646a8498 Mon Sep 17 00:00:00 2001 From: jprocter Date: Fri, 24 Mar 2006 10:21:36 +0000 Subject: [PATCH] developing streamReader tests. git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@206 be28352e-c001-0410-b1a7-c7978e42abec --- .../vamsas/client/simpleclient/VamsasArchive.java | 2 +- .../client/simpleclient/VamsasArchiveReader.java | 11 +++-- .../test/simpleclient/ArchiveStreamReader.java | 52 ++++++++++++++++++++ 3 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 src/org/vamsas/test/simpleclient/ArchiveStreamReader.java diff --git a/src/org/vamsas/client/simpleclient/VamsasArchive.java b/src/org/vamsas/client/simpleclient/VamsasArchive.java index 4c4fbfd..6e8138b 100644 --- a/src/org/vamsas/client/simpleclient/VamsasArchive.java +++ b/src/org/vamsas/client/simpleclient/VamsasArchive.java @@ -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); } } diff --git a/src/org/vamsas/client/simpleclient/VamsasArchiveReader.java b/src/org/vamsas/client/simpleclient/VamsasArchiveReader.java index 3d4fbe6..d0476cd 100644 --- a/src/org/vamsas/client/simpleclient/VamsasArchiveReader.java +++ b/src/org/vamsas/client/simpleclient/VamsasArchiveReader.java @@ -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 index 0000000..1415731 --- /dev/null +++ b/src/org/vamsas/test/simpleclient/ArchiveStreamReader.java @@ -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); + } + } +} -- 1.7.10.2