From 1c472d54a12783c4be933b83d47217b7d56b167f Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Wed, 8 Mar 2006 16:51:44 +0000 Subject: [PATCH] Able to read resources from Zip file --- src/jalview/io/AnnotationReader.java | 21 ++++++++++++++------- src/jalview/io/AppletFormatAdapter.java | 7 +++++++ src/jalview/io/FileParse.java | 28 ++++++++++++---------------- src/jalview/io/IdentifyFile.java | 27 ++++++++++++++++----------- 4 files changed, 49 insertions(+), 34 deletions(-) diff --git a/src/jalview/io/AnnotationReader.java b/src/jalview/io/AnnotationReader.java index 958aa65..4325dae 100755 --- a/src/jalview/io/AnnotationReader.java +++ b/src/jalview/io/AnnotationReader.java @@ -13,18 +13,25 @@ public class AnnotationReader try { - BufferedReader in = null; - try{ - URL url = new URL(file); - in = new BufferedReader(new InputStreamReader(url.openStream())); + java.io.InputStream is = getClass().getResourceAsStream("/" + file); + if (is != null) + { + in = new BufferedReader(new java.io.InputStreamReader(is)); } - catch(java.net.MalformedURLException ex) + else { - in = new BufferedReader(new FileReader(file)); + try + { + URL url = new URL(file); + in = new BufferedReader(new InputStreamReader(url.openStream())); + } + catch (java.net.MalformedURLException ex) + { + in = new BufferedReader(new FileReader(file)); + } } - String line, label, description, token; int graphStyle, index; SequenceI refSeq = null; diff --git a/src/jalview/io/AppletFormatAdapter.java b/src/jalview/io/AppletFormatAdapter.java index dca2d0c..5f73898 100755 --- a/src/jalview/io/AppletFormatAdapter.java +++ b/src/jalview/io/AppletFormatAdapter.java @@ -50,6 +50,12 @@ formats.addElement("PFAM"); } + + public static String FILE = "File"; + public static String URL = "URL"; + public static String PASTE = "Paste"; + public static String CLASSLOADER = "ClassLoader"; + AlignFile afile = null; /** @@ -95,6 +101,7 @@ afile = new PfamFile(inFile, type); } + return afile.getSeqsAsArray(); } catch (Exception e) diff --git a/src/jalview/io/FileParse.java b/src/jalview/io/FileParse.java index af3bbec..adc57cd 100755 --- a/src/jalview/io/FileParse.java +++ b/src/jalview/io/FileParse.java @@ -24,8 +24,6 @@ import java.net.*; public class FileParse { public File inFile; - public int fileSize; - public int noLines; protected String type; protected BufferedReader dataIn; @@ -38,35 +36,33 @@ public class FileParse { this.type = type; - if (type.equals("File")) + if (type.equals(AppletFormatAdapter.FILE)) { this.inFile = new File(fileStr); - this.fileSize = (int) inFile.length(); - dataIn = new BufferedReader(new FileReader(fileStr)); } - else if (type.equals("URL")) + else if (type.equals(AppletFormatAdapter.URL)) { URL url = new URL(fileStr); - this.fileSize = 0; dataIn = new BufferedReader(new InputStreamReader(url.openStream())); } - else if (type.equals("Paste")) + else if (type.equals(AppletFormatAdapter.PASTE)) { dataIn = new BufferedReader(new StringReader(fileStr)); } + else if (type.equals(AppletFormatAdapter.CLASSLOADER)) + { + java.io.InputStream is = getClass().getResourceAsStream("/" + fileStr); + if (is != null) + { + dataIn = new BufferedReader(new java.io.InputStreamReader(is)); + } + } } public String nextLine() throws IOException { - String next = dataIn.readLine(); - - if (next != null) - { - noLines++; - } - - return next; + return dataIn.readLine(); } } diff --git a/src/jalview/io/IdentifyFile.java b/src/jalview/io/IdentifyFile.java index f4beccb..2040769 100755 --- a/src/jalview/io/IdentifyFile.java +++ b/src/jalview/io/IdentifyFile.java @@ -39,30 +39,35 @@ public class IdentifyFile * * @return DOCUMENT ME! */ - public static String Identify(String file, String protocol) + public String Identify(String file, String protocol) { String reply = "PFAM"; String error = "FILE NOT FOUND"; - try { BufferedReader reader = null; - if (protocol.equalsIgnoreCase("File")) + if (protocol.equals(AppletFormatAdapter.FILE)) { - reader = new BufferedReader(new FileReader(file)); + reader = new BufferedReader(new FileReader(file)); } - else if (protocol.equalsIgnoreCase("URL")) + else if (protocol.equals(AppletFormatAdapter.URL)) { - error = "URL NOT FOUND"; - URL url = new URL(file); - reader = new BufferedReader(new InputStreamReader( - url.openStream())); + error = "URL NOT FOUND"; + URL url = new URL(file); + reader = new BufferedReader(new InputStreamReader( + url.openStream())); } - else if (protocol.equalsIgnoreCase("Paste")) + else if (protocol.equals(AppletFormatAdapter.PASTE)) + { + reader = new BufferedReader(new StringReader(file)); + } + else if (protocol.equals(AppletFormatAdapter.CLASSLOADER)) { - reader = new BufferedReader(new StringReader(file)); + java.io.InputStream is = getClass().getResourceAsStream("/" + + file); + reader = new BufferedReader(new java.io.InputStreamReader(is)); } String data; -- 1.7.10.2