1 package org.vamsas.test.simpleclient;
3 import java.io.BufferedInputStream;
5 import java.io.InputStream;
6 import java.io.InputStreamReader;
8 import org.vamsas.client.simpleclient.VamsasArchiveReader;
9 import org.vamsas.objects.core.ApplicationData;
10 import org.vamsas.objects.core.VAMSAS;
11 import org.vamsas.objects.core.VamsasDocument;
13 public class ArchiveReader {
14 public static boolean reportDocument(VamsasDocument document, VamsasArchiveReader archive) {
16 System.out.print("Vamsas Document version '"+document.getVersion()+"'");
17 System.out.print("Document contains "+document.getVAMSASCount()+" VAMSAS Elements and "+document.getApplicationDataCount()+" elements.\n");
18 if (document.getApplicationDataCount()>0) {
19 System.out.print("There are "+document.getApplicationDataCount()+" ApplicationData references.\n");
20 ApplicationData appd[] = document.getApplicationData();
21 for (int i=0,j=appd.length; i<j; i++) {
22 System.out.print("Application "+i+": '"+appd[i].getName()+"'\nVersion '"+appd[i].getVersion()+"'\nURN: '"+appd[i].getUrn()+"'\n");
23 System.out.print("AppData is ");
24 if (appd[i].getAppDataChoice().getDataReference()==null) {
25 String appData=appd[i].getAppDataChoice().getData();
26 if (appData.length()>1) {
27 System.out.print("a reference ("+appData+")");
29 if ((jstrm=archive.getAppdataStream(appData))!=null)
30 System.out.println(" which resolves to a JarEntry.");
32 System.out.println(" which does not resolve to a JarEntry.");
33 System.err.println("Unresolved appdata reference '"+appData+"'");
36 System.out.println("an empty reference.");
39 System.out.println("an embedded chunk of "+appd[i].getAppDataChoice().getDataReference().length+" bytes.");
46 System.out.print("Document Object is null");
51 public static boolean rootReport(VAMSAS[] roots) {
53 for (int i=0; i<roots.length; i++) {
55 System.out.print("Vamsas Root "+i+" (id="
56 +((r.getId()!=null) ? r.getId():"<none>")
57 +") contains "+r.getDataSetCount()+" DataSets, "
58 + r.getTreeCount()+" Global trees");
65 public static void main(String args[]) {
68 File av = new File(args[0]);
69 VamsasArchiveReader var = new VamsasArchiveReader(av);
72 InputStreamReader vdoc = new InputStreamReader(var.getVamsasDocumentStream());
73 VamsasDocument doc = VamsasDocument.unmarshal(vdoc);
74 if (reportDocument(doc, var)) {
75 roots = doc.getVAMSAS();
78 InputStream vxmlis = var.getVamsasXmlStream();
80 if (vxmlis!=null) { // Might be an old vamsas file.
81 BufferedInputStream ixml = new BufferedInputStream(var.getVamsasXmlStream());
82 InputStreamReader vxml = new InputStreamReader(ixml);
84 // unmarshal seems to always close the stream (should check this)
85 if ((root = VAMSAS.unmarshal(vxml))!=null) {
86 System.out.println("Read a root.");
87 roots = new VAMSAS[1];
92 if (!rootReport(roots))
93 System.err.print(args[0]+" is not a valid vamsas archive.");
94 } catch (Exception e) {
95 e.printStackTrace(System.err);