applied LGPLv3 and source code formatting.
[vamsas.git] / src / uk / ac / vamsas / test / simpleclient / ArchiveReader.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.VamsasArchiveReader;\r
30 import uk.ac.vamsas.objects.core.VAMSAS;\r
31 import uk.ac.vamsas.objects.core.VamsasDocument;\r
32 \r
33 public class ArchiveReader {\r
34   /**\r
35    * tests VamsasArchiveReader archive reader on a vamsas jar file\r
36    * \r
37    * @param args\r
38    */\r
39   public static void main(String args[]) {\r
40 \r
41     try {\r
42       File av = new File(args[0]);\r
43       VamsasArchiveReader var = new VamsasArchiveReader(av);\r
44       VAMSAS roots[] = null;\r
45       if (var.isValid()) {\r
46         InputStreamReader vdoc = new InputStreamReader(var\r
47             .getVamsasDocumentStream());\r
48         VamsasDocument doc = VamsasDocument.unmarshal(vdoc);\r
49         if (ArchiveReports.reportDocument(doc, var, true, System.out)) {\r
50           roots = doc.getVAMSAS();\r
51         }\r
52       } else {\r
53         InputStream vxmlis = var.getVamsasXmlStream();\r
54 \r
55         if (vxmlis != null) { // Might be an old vamsas file.\r
56           BufferedInputStream ixml = new BufferedInputStream(var\r
57               .getVamsasXmlStream());\r
58           InputStreamReader vxml = new InputStreamReader(ixml);\r
59           VAMSAS root;\r
60           // unmarshal seems to always close the stream (should check this)\r
61           if ((root = VAMSAS.unmarshal(vxml)) != null) {\r
62             System.out.println("Read a root.");\r
63             roots = new VAMSAS[1];\r
64             roots[0] = root;\r
65           }\r
66         }\r
67       }\r
68       if (!ArchiveReports.rootReport(roots, true, System.out))\r
69         System.err.print(args[0] + " is not a valid vamsas archive.");\r
70     } catch (Exception e) {\r
71       e.printStackTrace(System.err);\r
72     }\r
73   }\r
74 }\r