a860e0eafd0ac60e0b6b68ec0d8809bbdb6b5a47
[vamsas.git] / src / uk / ac / vamsas / test / simpleclient / ZipTest.java
1 package uk.ac.vamsas.test.simpleclient;\r
2 \r
3 import java.io.File;\r
4 import java.util.jar.JarFile;\r
5 /**\r
6  * really simple test to see if we can open an archive and test for the existence of\r
7  * an entry called vamssDocument.xml.\r
8  * \r
9  * 'Pathological' archives fail this test (due to things like funny characters or lots of '.' in the entry name.\r
10  * \r
11  * @author JimP\r
12  *\r
13  */\r
14 public class ZipTest {\r
15 \r
16   /**\r
17    * @param args single filename as an argument to open as a Jar file.\r
18    */\r
19   public static void main(String[] args) {\r
20     File av = new File(args[0]);\r
21     boolean jfailed=false;\r
22     try {\r
23       JarFile jf = new JarFile(av, false, JarFile.OPEN_READ);\r
24       if (jf.getEntry("vamsasDocument.xml")!=null)\r
25       {\r
26         System.out.println("Valid archive "+av);\r
27       }\r
28       jf.close();\r
29       return;\r
30     } catch (Exception f)\r
31     {\r
32       System.out.println("Couldn't access jar archive "+av);\r
33       f.printStackTrace(System.out);\r
34     }\r
35     try {\r
36       System.out.println("Trying the Apache Zip Package:");\r
37       org.apache.tools.zip.ZipFile jf = new org.apache.tools.zip.ZipFile(av);\r
38       if (jf.getEntry("vamsasDocument.xml")!=null)\r
39       {\r
40         System.out.println("Valid archive "+av);\r
41       }\r
42       jf.close();\r
43     } catch (Exception f)\r
44     {\r
45       System.out.println("Couldn't access jar archive "+av);\r
46       f.printStackTrace(System.out);\r
47     }\r
48   }\r
49 }\r