X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FIdentifyFile.java;h=86036fde9cef0107ace8392e3f5e21444246b907;hb=cab9f54d732ed7b127140efd5f3b923accd10eb4;hp=a8d93d53908fc0fbe5338ed803ecf6801276ceae;hpb=bf137b6f217be9b0ffa1d6e8a71fdc563f17ef89;p=jalview.git diff --git a/src/jalview/io/IdentifyFile.java b/src/jalview/io/IdentifyFile.java index a8d93d5..86036fd 100755 --- a/src/jalview/io/IdentifyFile.java +++ b/src/jalview/io/IdentifyFile.java @@ -66,10 +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)) @@ -136,10 +164,10 @@ public class IdentifyFile } else { - reply = "FASTA"; + reply = "FASTA"; + // TODO : AMSA File is indicated if there is annotation in the FASTA file - but FASTA will automatically generate this at the mo. } } - break; } else if (data.indexOf("HEADER") == 0 || @@ -157,18 +185,6 @@ public class IdentifyFile reply = "JnetFile"; break; } - else if (source.inFile!=null) - { - String fileStr=source.inFile.getName(); - // possibly a Jalview archive. - if (fileStr.lastIndexOf(".jar")>-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 } @@ -183,7 +199,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 [ ...]"); + } + } }