applied LGPLv3 and source code formatting.
[vamsas.git] / src / uk / ac / vamsas / test / simpleclient / ZipTest.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.File;\r
25 import java.util.jar.JarFile;\r
26 \r
27 /**\r
28  * really simple test to see if we can open an archive and test for the\r
29  * existence of an entry called vamssDocument.xml.\r
30  * \r
31  * 'Pathological' archives fail this test (due to things like funny characters\r
32  * or lots of '.' in the entry name.\r
33  * \r
34  * @author JimP\r
35  * \r
36  */\r
37 public class ZipTest {\r
38 \r
39   /**\r
40    * @param args\r
41    *          single filename as an argument to open as a Jar file.\r
42    */\r
43   public static void main(String[] args) {\r
44     File av = new File(args[0]);\r
45     boolean jfailed = false;\r
46     try {\r
47       JarFile jf = new JarFile(av, false, JarFile.OPEN_READ);\r
48       if (jf.getEntry("vamsasDocument.xml") != null) {\r
49         System.out.println("Valid archive " + av);\r
50       }\r
51       jf.close();\r
52       return;\r
53     } catch (Exception f) {\r
54       System.out.println("Couldn't access jar archive " + av);\r
55       f.printStackTrace(System.out);\r
56     }\r
57     try {\r
58       System.out.println("Trying the Apache Zip Package:");\r
59       org.apache.tools.zip.ZipFile jf = new org.apache.tools.zip.ZipFile(av);\r
60       if (jf.getEntry("vamsasDocument.xml") != null) {\r
61         System.out.println("Valid archive " + av);\r
62       }\r
63       jf.close();\r
64     } catch (Exception f) {\r
65       System.out.println("Couldn't access jar archive " + av);\r
66       f.printStackTrace(System.out);\r
67     }\r
68   }\r
69 }\r