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.VamsasArchiveReader; import org.vamsas.objects.core.ApplicationData; import org.vamsas.objects.core.VAMSAS; import org.vamsas.objects.core.VamsasDocument; public class ArchiveReader { public static boolean reportDocument(VamsasDocument document, VamsasArchiveReader archive) { if (document!=null) { System.out.print("Vamsas Document version '"+document.getVersion()+"'"); System.out.print("Document contains "+document.getVAMSASCount()+" VAMSAS Elements and "+document.getApplicationDataCount()+" elements.\n"); if (document.getApplicationDataCount()>0) { System.out.print("There are "+document.getApplicationDataCount()+" ApplicationData references.\n"); ApplicationData appd[] = document.getApplicationData(); for (int i=0,j=appd.length; i1) { System.out.print("a reference ("+appData+")"); InputStream jstrm; if ((jstrm=archive.getAppdataStream(appData))!=null) System.out.println(" which resolves to a JarEntry."); else { System.out.println(" which does not resolve to a JarEntry."); System.err.println("Unresolved appdata reference '"+appData+"'"); } } else { System.out.println("an empty reference."); } } else { System.out.println("an embedded chunk of "+appd[i].getAppDataChoice().getData().length+" bytes."); } } } return true; } else { System.out.print("Document Object is null"); } return false; } public static boolean rootReport(VAMSAS[] roots) { if (roots!=null) { for (int i=0; i") +") contains "+r.getDataSetCount()+" DataSets, " + r.getTreeCount()+" Global trees"); } return true; } return false; } public static void main(String args[]) { try { File av = new File(args[0]); VamsasArchiveReader var = new VamsasArchiveReader(av); VAMSAS roots[]=null; if (var.isValid()) { InputStreamReader vdoc = new InputStreamReader(var.getVamsasDocumentStream()); VamsasDocument doc = VamsasDocument.unmarshal(vdoc); if (reportDocument(doc, var)) { 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 (!rootReport(roots)) System.err.print(args[0]+" is not a valid vamsas archive."); } catch (Exception e) { e.printStackTrace(System.err); } } }