X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FIdentifyFile.java;h=7293ac6927a9310c8dc49e54f3ffca815efeb765;hb=4932106f045349290d58ab38d216dff31fd9afce;hp=7f3db40720fda78e4b677235514f8715ed01c61e;hpb=e8b5b1e551794bf54de00c610363ffd140c62e55;p=jalview.git diff --git a/src/jalview/io/IdentifyFile.java b/src/jalview/io/IdentifyFile.java index 7f3db40..7293ac6 100755 --- a/src/jalview/io/IdentifyFile.java +++ b/src/jalview/io/IdentifyFile.java @@ -66,9 +66,38 @@ public class IdentifyFile public String Identify(FileParse source, boolean closeSource) { String reply = "PFAM"; String data; + int length=0; + boolean lineswereskipped=false; + boolean isBinary = false; // true if length is non-zero and non-printable characters are encountered try { while ( (data = source.nextLine()) != null) { + length+=data.length(); + if (!lineswereskipped) + { + for (int i=0;!isBinary && i-1 || fileStr.lastIndexOf(".zip")>-1) + { + reply = "Jalview"; + } + } + if (!lineswereskipped && data.startsWith("PK")) { + reply="Jalview"; // archive. + break; + } + } data = data.toUpperCase(); if ( (data.indexOf("# STOCKHOLM") > -1)) @@ -78,8 +107,9 @@ public class IdentifyFile break; } - if ( (data.indexOf("#") == 0) || (data.length() < 1)) + if ((data.length() < 1) || (data.indexOf("#") == 0)) { + lineswereskipped=true; continue; } @@ -134,10 +164,9 @@ public class IdentifyFile } else { - reply = "FASTA"; + reply = "FASTA"; } } - break; } else if (data.indexOf("HEADER") == 0 || @@ -146,24 +175,17 @@ public class IdentifyFile reply = "PDB"; break; } - else if (data.indexOf(":") < data.indexOf(",")) // && data.indexOf(",")-1 || fileStr.lastIndexOf(".zip")>-1) - { - reply = "Jalview"; - } - } else if (data.startsWith("PK")) { - reply="Jalview"; // archive. - break; - } + + lineswereskipped=true; // this means there was some junk before any key file signature } if (closeSource) { source.close(); @@ -176,7 +198,23 @@ public class IdentifyFile System.err.println("File Identification failed!\n" + ex); return source.errormessage; } - + if (length==0) + { + System.err.println("File Identification failed! - Empty file was read."); + return "EMPTY DATA FILE"; + } return reply; } + public static void main(String[] args) { + for (int i=0; args!=null && i [ ...]"); + } + } }