X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FIdentifyFile.java;h=729a86040aab30234553b705008803d08c1d5da9;hb=93020ed6ef8dd285c987f79d258508bd53187433;hp=2442b4bb142254b668fd1e6fd908b52ed8834ade;hpb=588042b69abf8e60bcc950b24c283933c7dd422f;p=jalview.git diff --git a/src/jalview/io/IdentifyFile.java b/src/jalview/io/IdentifyFile.java index 2442b4b..729a860 100755 --- a/src/jalview/io/IdentifyFile.java +++ b/src/jalview/io/IdentifyFile.java @@ -23,37 +23,61 @@ import java.io.*; import java.net.*; -public class IdentifyFile { - public static String Identify(String file, String protocol) { +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ +public class IdentifyFile +{ + /** + * DOCUMENT ME! + * + * @param file DOCUMENT ME! + * @param protocol DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public static String Identify(String file, String protocol) + { String reply = "PFAM"; + String error = "FILE NOT FOUND"; - try { + try + { BufferedReader reader = null; - if (protocol.equals("File")) { + if (protocol.equalsIgnoreCase("File")) + { reader = new BufferedReader(new FileReader(file)); } - else if (protocol.equals("URL")) { - reply = "URL NOT FOUND"; - + else if (protocol.equalsIgnoreCase("URL")) + { + error = "URL NOT FOUND"; URL url = new URL(file); reader = new BufferedReader(new InputStreamReader( url.openStream())); - reply = "error"; - } else if (protocol.equals("Paste")) { + + } + else if (protocol.equalsIgnoreCase("Paste")) + { reader = new BufferedReader(new StringReader(file)); } String data; - while ((data = reader.readLine()) != null) { + while ((data = reader.readLine()) != null) + { data = data.toUpperCase(); - if ((data.indexOf("#") == 0) || (data.length() < 1)) { + if ((data.indexOf("#") == 0) || (data.length() < 1)) + { continue; } - if (data.indexOf("PILEUP") > -1) { + if (data.indexOf("PILEUP") > -1) + { reply = "PileUp"; break; @@ -62,26 +86,36 @@ public class IdentifyFile { if ((data.indexOf("//") == 0) || ((data.indexOf("!!") > -1) && (data.indexOf("!!") < data.indexOf( - "_MULTIPLE_ALIGNMENT ")))) { + "_MULTIPLE_ALIGNMENT ")))) + { reply = "MSF"; break; - } else if (data.indexOf("CLUSTAL") > -1) { + } + else if (data.indexOf("CLUSTAL") > -1) + { reply = "CLUSTAL"; break; - } else if ((data.indexOf(">P1;") > -1) || - (data.indexOf(">DL;") > -1)) { + } + else if ((data.indexOf(">P1;") > -1) || + (data.indexOf(">DL;") > -1)) + { reply = "PIR"; break; - } else if (data.indexOf(">") > -1) { + } + else if (data.indexOf(">") > -1) + { // could be BLC file, read next line to confirm data = reader.readLine(); - if (data.indexOf(">") > -1) { + if (data.indexOf(">") > -1) + { reply = "BLC"; - } else { + } + else + { reply = "FASTA"; } @@ -90,10 +124,12 @@ public class IdentifyFile { } reader.close(); - } catch (Exception ex) { + } + catch (Exception ex) + { System.err.println("File Identification failed!\n" + ex); + return error; } - return reply; } }