X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FIdentifyFile.java;h=baee5314c0f4193245b0aecce67610eb108b0b1c;hb=85299bc2db43c8b108169661ebc1c4d9b2d3d2e5;hp=c21127ee201140c2b12bded740ab3278afd648c1;hpb=57738a1f3c19b1c3a00bd3ac5108f8cd0af32f99;p=jalview.git diff --git a/src/jalview/io/IdentifyFile.java b/src/jalview/io/IdentifyFile.java index c21127e..baee531 100755 --- a/src/jalview/io/IdentifyFile.java +++ b/src/jalview/io/IdentifyFile.java @@ -20,10 +20,11 @@ */ package jalview.io; -import java.util.Locale; - import java.io.File; import java.io.IOException; +import java.util.Locale; + +import jalview.bin.Console; /** * DOCUMENT ME! @@ -34,6 +35,8 @@ import java.io.IOException; public class IdentifyFile { + private static final String XMLHEADER = ""; + public FileFormatI identify(Object file, DataSourceType protocol) throws FileFormatException { @@ -58,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) @@ -94,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) @@ -135,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 @@ -189,6 +191,10 @@ public class IdentifyFile reply = FileFormat.ScoreMatrix; break; } + if (data.startsWith(XMLHEADER) && !lineswereskipped) + { + isXml = true; + } if (data.startsWith("LOCUS")) { reply = FileFormat.GenBank; @@ -347,6 +353,12 @@ public class IdentifyFile reply = FileFormat.Rnaml; break; } + if (isXml && data.contains( + "")) + { + reply = FileFormat.FeatureSettings; + break; + } } if ((data.length() < 1) || (data.indexOf("#") == 0)) @@ -408,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; } @@ -485,15 +496,15 @@ 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: [ ...]"); } }