X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FIdentifyFile.java;h=baee5314c0f4193245b0aecce67610eb108b0b1c;hb=a9177efb4097815d9a8031aa22700c61a7d6260a;hp=e7ee711989df0c4de8228147e5f57f0f37b4c493;hpb=f42cec3b999bbed0ce85045760b55701c527da32;p=jalview.git diff --git a/src/jalview/io/IdentifyFile.java b/src/jalview/io/IdentifyFile.java index e7ee711..baee531 100755 --- a/src/jalview/io/IdentifyFile.java +++ b/src/jalview/io/IdentifyFile.java @@ -22,6 +22,9 @@ package jalview.io; import java.io.File; import java.io.IOException; +import java.util.Locale; + +import jalview.bin.Console; /** * DOCUMENT ME! @@ -31,12 +34,16 @@ import java.io.IOException; */ public class IdentifyFile { - - public FileFormatI identify(Object file, DataSourceType protocol) throws FileFormatException + + private static final String XMLHEADER = ""; + + public FileFormatI identify(Object file, DataSourceType protocol) + throws FileFormatException { // BH 2018 - return (file instanceof File ? identify((File) file, protocol) : identify((String) file, protocol)); - + return (file instanceof File ? identify((File) file, protocol) + : identify((String) file, protocol)); + } public FileFormatI identify(File file, DataSourceType sourceType) @@ -54,8 +61,7 @@ public class IdentifyFile } } catch (Exception e) { - System.err.println("Error whilst identifying " + file); - e.printStackTrace(System.err); + Console.error("Error whilst identifying " + file, e); emessage = e.getMessage(); } if (parser != null) @@ -90,8 +96,7 @@ public class IdentifyFile } } catch (Exception e) { - System.err.println("Error whilst identifying " + file); - e.printStackTrace(System.err); + Console.error("Error whilst identifying " + file, e); emessage = e.getMessage(); } if (parser != null) @@ -131,6 +136,7 @@ public class IdentifyFile String data; int bytesRead = 0; int trimmedLength = 0; + boolean isXml = false; // set true if first line is XMLHEADER boolean lineswereskipped = false; boolean isBinary = false; // true if length is non-zero and non-printable // characters are encountered @@ -165,8 +171,8 @@ public class IdentifyFile if (source.inFile != null) { String fileStr = source.inFile.getName(); - if (fileStr.contains(".jar") - || fileStr.contains(".zip") || fileStr.contains(".jvp")) + if (fileStr.contains(".jar") || fileStr.contains(".zip") + || fileStr.contains(".jvp")) { // possibly a Jalview archive (but check further) reply = FileFormat.Jalview; @@ -178,13 +184,17 @@ public class IdentifyFile break; } } - data = data.toUpperCase(); + data = data.toUpperCase(Locale.ROOT); if (data.startsWith(ScoreMatrixFile.SCOREMATRIX)) { reply = FileFormat.ScoreMatrix; break; } + if (data.startsWith(XMLHEADER) && !lineswereskipped) + { + isXml = true; + } if (data.startsWith("LOCUS")) { reply = FileFormat.GenBank; @@ -332,7 +342,7 @@ public class IdentifyFile if ((lessThan > -1)) // possible Markup Language data i.e HTML, // RNAML, XML { - String upper = data.toUpperCase(); + String upper = data.toUpperCase(Locale.ROOT); if (upper.substring(lessThan).startsWith("")) + { + reply = FileFormat.FeatureSettings; + break; + } } if ((data.length() < 1) || (data.indexOf("#") == 0)) @@ -404,16 +420,15 @@ public class IdentifyFile } } catch (Exception ex) { - System.err.println("File Identification failed!\n" + ex); + Console.error("File Identification failed!\n" + ex); throw new FileFormatException(source.errormessage); } if (trimmedLength == 0) { - System.err.println( - "File Identification failed! - Empty file was read."); + Console.error("File Identification failed! - Empty file was read."); throw new FileFormatException("EMPTY DATA FILE"); } - System.out.println("File format identified as " + reply.toString()); + Console.debug("File format identified as " + reply.toString()); return reply; } @@ -481,17 +496,16 @@ public class IdentifyFile type = ider.identify(args[i], DataSourceType.FILE); } catch (FileFormatException e) { - System.err.println( + Console.error( String.format("Error '%s' identifying file type for %s", args[i], e.getMessage())); } - System.out.println("Type of " + args[i] + " is " + type); + Console.debug("Type of " + args[i] + " is " + type); } if (args == null || args.length == 0) { - System.err.println("Usage: [ ...]"); + Console.error("Usage: [ ...]"); } } - }