applied LGPLv3 and source code formatting.
[vamsas.git] / src / uk / ac / vamsas / test / simpleclient / ArchiveStreamReader.java
1 /*\r
2  * This file is part of the Vamsas Client version 0.1. \r
3  * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite, \r
4  *  Andrew Waterhouse and Dominik Lindner.\r
5  * \r
6  * Earlier versions have also been incorporated into Jalview version 2.4 \r
7  * since 2008, and TOPALi version 2 since 2007.\r
8  * \r
9  * The Vamsas Client is free software: you can redistribute it and/or modify\r
10  * it under the terms of the GNU Lesser General Public License as published by\r
11  * the Free Software Foundation, either version 3 of the License, or\r
12  * (at your option) any later version.\r
13  *  \r
14  * The Vamsas Client is distributed in the hope that it will be useful,\r
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
17  * GNU Lesser General Public License for more details.\r
18  * \r
19  * You should have received a copy of the GNU Lesser General Public License\r
20  * along with the Vamsas Client.  If not, see <http://www.gnu.org/licenses/>.\r
21  */\r
22 package uk.ac.vamsas.test.simpleclient;\r
23 \r
24 import java.io.BufferedInputStream;\r
25 import java.io.File;\r
26 import java.io.InputStream;\r
27 import java.io.InputStreamReader;\r
28 \r
29 import uk.ac.vamsas.client.simpleclient.SessionFile;\r
30 import uk.ac.vamsas.client.simpleclient.VamsasArchiveReader;\r
31 import uk.ac.vamsas.client.simpleclient.VamsasFile;\r
32 import uk.ac.vamsas.objects.core.VAMSAS;\r
33 import uk.ac.vamsas.objects.core.VamsasDocument;\r
34 \r
35 public class ArchiveStreamReader {\r
36   /**\r
37    * tests VamsasArchiveReader archive reader on a vamsas jar file opened as a\r
38    * stream\r
39    * \r
40    * @param args\r
41    */\r
42   public static void main(String args[]) {\r
43 \r
44     try {\r
45       VamsasFile av = new VamsasFile(new File(args[0]));\r
46       VamsasArchiveReader var = new VamsasArchiveReader(av.getLock());\r
47       VAMSAS roots[] = null;\r
48       if (var.isValid()) {\r
49         InputStreamReader vdoc = new InputStreamReader(var\r
50             .getVamsasDocumentStream());\r
51         VamsasDocument doc = VamsasDocument.unmarshal(vdoc);\r
52         if (ArchiveReports.reportDocument(doc, var, true, System.out)) {\r
53           roots = doc.getVAMSAS();\r
54         }\r
55       } else {\r
56         InputStream vxmlis = var.getVamsasXmlStream();\r
57 \r
58         if (vxmlis != null) { // Might be an old vamsas file.\r
59           BufferedInputStream ixml = new BufferedInputStream(var\r
60               .getVamsasXmlStream());\r
61           InputStreamReader vxml = new InputStreamReader(ixml);\r
62           VAMSAS root;\r
63           // unmarshal seems to always close the stream (should check this)\r
64           if ((root = VAMSAS.unmarshal(vxml)) != null) {\r
65             System.out.println("Read a root.");\r
66             roots = new VAMSAS[1];\r
67             roots[0] = root;\r
68           }\r
69         }\r
70       }\r
71       if (!ArchiveReports.rootReport(roots, true, System.out))\r
72         System.err.print(args[0] + " is not a valid vamsas archive.");\r
73     } catch (Exception e) {\r
74       e.printStackTrace(System.err);\r
75     }\r
76   }\r
77 }\r