From 4932106f045349290d58ab38d216dff31fd9afce Mon Sep 17 00:00:00 2001 From: jprocter Date: Wed, 9 May 2007 15:51:59 +0000 Subject: [PATCH] main method for running from command line and better binary file/archive detection --- src/jalview/io/IdentifyFile.java | 61 ++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 15 deletions(-) diff --git a/src/jalview/io/IdentifyFile.java b/src/jalview/io/IdentifyFile.java index a8d93d5..7293ac6 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,9 @@ public class IdentifyFile } else { - reply = "FASTA"; + reply = "FASTA"; } } - break; } else if (data.indexOf("HEADER") == 0 || @@ -157,18 +184,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 +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 [ ...]"); + } + } } -- 1.7.10.2