Able to read resources from Zip file
authoramwaterhouse <Andrew Waterhouse>
Wed, 8 Mar 2006 16:51:44 +0000 (16:51 +0000)
committeramwaterhouse <Andrew Waterhouse>
Wed, 8 Mar 2006 16:51:44 +0000 (16:51 +0000)
src/jalview/io/AnnotationReader.java
src/jalview/io/AppletFormatAdapter.java
src/jalview/io/FileParse.java
src/jalview/io/IdentifyFile.java

index 958aa65..4325dae 100755 (executable)
@@ -13,18 +13,25 @@ public class AnnotationReader
 \r
     try\r
     {\r
-\r
       BufferedReader in = null;\r
-      try{\r
-        URL url = new URL(file);\r
-        in = new BufferedReader(new InputStreamReader(url.openStream()));\r
+      java.io.InputStream is = getClass().getResourceAsStream("/" + file);\r
+      if (is != null)\r
+      {\r
+        in = new BufferedReader(new java.io.InputStreamReader(is));\r
       }\r
-      catch(java.net.MalformedURLException ex)\r
+      else\r
       {\r
-        in = new BufferedReader(new FileReader(file));\r
+        try\r
+        {\r
+          URL url = new URL(file);\r
+          in = new BufferedReader(new InputStreamReader(url.openStream()));\r
+        }\r
+        catch (java.net.MalformedURLException ex)\r
+        {\r
+          in = new BufferedReader(new FileReader(file));\r
+        }\r
       }\r
 \r
-\r
       String line, label, description, token;\r
       int graphStyle, index;\r
       SequenceI refSeq = null;\r
index dca2d0c..5f73898 100755 (executable)
             formats.addElement("PFAM");\r
         }\r
 \r
+\r
+        public static String FILE = "File";\r
+        public static String URL = "URL";\r
+        public static String PASTE = "Paste";\r
+        public static String CLASSLOADER = "ClassLoader";\r
+\r
         AlignFile afile = null;\r
 \r
         /**\r
                     afile = new PfamFile(inFile, type);\r
                 }\r
 \r
+\r
                 return afile.getSeqsAsArray();\r
             }\r
             catch (Exception e)\r
index af3bbec..adc57cd 100755 (executable)
@@ -24,8 +24,6 @@ import java.net.*;
 public class FileParse\r
 {\r
   public File inFile;\r
-  public int fileSize;\r
-  public int noLines;\r
   protected String type;\r
   protected BufferedReader dataIn;\r
 \r
@@ -38,35 +36,33 @@ public class FileParse
   {\r
     this.type = type;\r
 \r
-    if (type.equals("File"))\r
+    if (type.equals(AppletFormatAdapter.FILE))\r
     {\r
       this.inFile = new File(fileStr);\r
-      this.fileSize = (int) inFile.length();\r
-\r
       dataIn = new BufferedReader(new FileReader(fileStr));\r
     }\r
-    else if (type.equals("URL"))\r
+    else if (type.equals(AppletFormatAdapter.URL))\r
     {\r
       URL url = new URL(fileStr);\r
-      this.fileSize = 0;\r
       dataIn = new BufferedReader(new InputStreamReader(url.openStream()));\r
     }\r
-    else if (type.equals("Paste"))\r
+   else if (type.equals(AppletFormatAdapter.PASTE))\r
     {\r
       dataIn = new BufferedReader(new StringReader(fileStr));\r
     }\r
+    else if (type.equals(AppletFormatAdapter.CLASSLOADER))\r
+    {\r
+      java.io.InputStream is = getClass().getResourceAsStream("/" + fileStr);\r
+      if (is != null)\r
+      {\r
+        dataIn = new BufferedReader(new java.io.InputStreamReader(is));\r
+      }\r
+    }\r
   }\r
 \r
   public String nextLine()\r
       throws IOException\r
   {\r
-    String next = dataIn.readLine();\r
-\r
-    if (next != null)\r
-    {\r
-      noLines++;\r
-    }\r
-\r
-    return next;\r
+    return dataIn.readLine();\r
   }\r
 }\r
index f4beccb..2040769 100755 (executable)
@@ -39,30 +39,35 @@ public class IdentifyFile
      *\r
      * @return DOCUMENT ME!\r
      */\r
-    public static String Identify(String file, String protocol)\r
+    public String Identify(String file, String protocol)\r
     {\r
         String reply = "PFAM";\r
         String error =  "FILE NOT FOUND";\r
-\r
         try\r
         {\r
             BufferedReader reader = null;\r
 \r
-            if (protocol.equalsIgnoreCase("File"))\r
+            if (protocol.equals(AppletFormatAdapter.FILE))\r
             {\r
-                reader = new BufferedReader(new FileReader(file));\r
+              reader = new BufferedReader(new FileReader(file));\r
             }\r
-            else if (protocol.equalsIgnoreCase("URL"))\r
+            else if (protocol.equals(AppletFormatAdapter.URL))\r
             {\r
-                error = "URL NOT FOUND";\r
-                URL url = new URL(file);\r
-                reader = new BufferedReader(new InputStreamReader(\r
-                            url.openStream()));\r
+              error = "URL NOT FOUND";\r
+              URL url = new URL(file);\r
+              reader = new BufferedReader(new InputStreamReader(\r
+                  url.openStream()));\r
 \r
             }\r
-            else if (protocol.equalsIgnoreCase("Paste"))\r
+            else if (protocol.equals(AppletFormatAdapter.PASTE))\r
+            {\r
+              reader = new BufferedReader(new StringReader(file));\r
+            }\r
+            else if (protocol.equals(AppletFormatAdapter.CLASSLOADER))\r
             {\r
-                reader = new BufferedReader(new StringReader(file));\r
+              java.io.InputStream is = getClass().getResourceAsStream("/" +\r
+                  file);\r
+              reader = new BufferedReader(new java.io.InputStreamReader(is));\r
             }\r
 \r
             String data;\r