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);
34 * name of the jarEntry containing a well formatted vamsas XML Document
37 final public static String VAMSASDOC="vamsasDocument.xml";
40 * name of the jarEntry containing a root VAMSAS element, and containing a
41 * random sequence of VAMSAS DataSet elements
44 final public static String VAMSASXML="vamsas.xml";
48 * @return JarEntry for VamsasArchiveReader.VAMSASDOC
50 protected JarEntry getVamsasDocumentEntry() {
52 return jfile.getJarEntry(VAMSASDOC);
57 * @return JarEntry for VamsasArchiveReader.VAMSASXML
59 protected JarEntry getVamsasXmlEntry() {
61 return jfile.getJarEntry(VAMSASXML);
65 * Test for valid vamsas document archive
66 * @return true if getVamsasDocumentStream will return a stream likely to contain valid XML
68 public boolean isValid() {
70 // 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
71 return (getVamsasDocumentEntry()!=null);
76 * get the VamsasDocument input stream, if it exists.
77 * @return null or valid input stream
79 public InputStream getVamsasDocumentStream() {
81 if (jfile==null || !isValid())
84 vdoc = jfile.getInputStream(getVamsasDocumentEntry());
85 } catch (IOException e) {
86 e.printStackTrace(System.err);
93 * get the VamsasXML input stream, if it exists.
94 * Note: Deprecated beyond our prealpha testing.
95 * @return null or valid input stream.
98 public InputStream getVamsasXmlStream() {
99 JarEntry xmle=getVamsasXmlEntry();
104 vdoc = jfile.getInputStream(xmle);
105 } catch (IOException e) {
106 e.printStackTrace(System.err);
113 * silently close the jar file.
116 public void close() {
120 } catch (IOException e) {
121 e.printStackTrace(System.err);