1 package org.vamsas.client.simpleclient;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.util.Iterator;
7 import java.util.jar.JarEntry;
8 import java.util.jar.JarFile;
9 import java.util.jar.JarInputStream;
10 import java.util.jar.JarOutputStream;
12 * Basic methods for accessing an existing Vamsas Archive,
13 * and Jar entry names for creating new vamsas archives.
18 public class VamsasArchiveReader {
20 public VamsasArchiveReader(File vamsasfile) {
22 if (vamsasfile.exists()) {
24 jfile=new JarFile(vamsasfile);
33 * the vamsas document version(s) handled by this Reader
35 final public static String DOCUMENT_VERSION="0.1";
37 * name of the jarEntry containing a well formatted vamsas XML Document
40 final public static String VAMSASDOC="vamsasDocument.xml";
43 * name of the jarEntry containing a root VAMSAS element, and containing a
44 * random sequence of VAMSAS DataSet elements
47 final public static String VAMSASXML="vamsas.xml";
51 * @return JarEntry for VamsasArchiveReader.VAMSASDOC
53 protected JarEntry getVamsasDocumentEntry() {
55 return jfile.getJarEntry(VAMSASDOC);
60 * @return JarEntry for VamsasArchiveReader.VAMSASXML
62 protected JarEntry getVamsasXmlEntry() {
64 return jfile.getJarEntry(VAMSASXML);
68 * Test for valid vamsas document archive
69 * @return true if getVamsasDocumentStream will return a stream likely to contain valid XML
71 public boolean isValid() {
73 // TODO: check if VAMSASDOC is well formed (follows www.vamsas.ac.uk/schemas/vamsasDocument.xsd) and all appData references are resolvable - preferably as jar entries
74 return (getVamsasDocumentEntry()!=null);
79 protected JarEntry getAppdataEntry(String AppdataRef) {
81 if (jfile==null || !isValid() || (entry=jfile.getJarEntry(AppdataRef))==null)
86 public InputStream getAppdataStream(String AppdataRef) {
87 JarEntry entry=getAppdataEntry(AppdataRef);
90 return jfile.getInputStream(entry);
91 } catch (IOException e) {
92 System.err.println("Failed when opening AppdataStream for "+AppdataRef);
93 e.printStackTrace(System.err);
98 * get the VamsasDocument input stream, if it exists.
99 * @return null or valid input stream
101 public InputStream getVamsasDocumentStream() {
103 if (jfile==null || !isValid())
106 vdoc = jfile.getInputStream(getVamsasDocumentEntry());
107 } catch (IOException e) {
108 e.printStackTrace(System.err);
115 * get the VamsasXML input stream, if it exists.
116 * Note: Deprecated beyond our prealpha testing.
117 * @return null or valid input stream.
120 public InputStream getVamsasXmlStream() {
121 JarEntry xmle=getVamsasXmlEntry();
126 vdoc = jfile.getInputStream(xmle);
127 } catch (IOException e) {
128 e.printStackTrace(System.err);
135 * silently close the jar file.
138 public void close() {
142 } catch (IOException e) {
143 e.printStackTrace(System.err);