X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FIdentifyFile.java;fp=src%2Fjalview%2Fio%2FIdentifyFile.java;h=8251c2276a19243703f1b3ad2095ae4b924243ee;hb=e83ce5d8ef826fc0b509a51f154abdf734501077;hp=ea870582e3f3f5eef6c3e8a3a39e1f90b20b6791;hpb=786475501a15799d7c4058dbf74e4bf896d03736;p=jalview.git diff --git a/src/jalview/io/IdentifyFile.java b/src/jalview/io/IdentifyFile.java index ea87058..8251c22 100755 --- a/src/jalview/io/IdentifyFile.java +++ b/src/jalview/io/IdentifyFile.java @@ -21,6 +21,7 @@ package jalview.io; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import java.util.Locale; @@ -35,8 +36,10 @@ import jalview.bin.Console; public class IdentifyFile { + private static final String XMLHEADER = ""; + public FileFormatI identify(Object file, DataSourceType protocol) - throws FileFormatException + throws FileFormatException, FileNotFoundException { // BH 2018 return (file instanceof File ? identify((File) file, protocol) @@ -81,10 +84,11 @@ public class IdentifyFile * @throws FileFormatException */ public FileFormatI identify(String file, DataSourceType sourceType) - throws FileFormatException + throws FileFormatException, FileNotFoundException { String emessage = "UNIDENTIFIED FILE PARSING ERROR"; FileParse parser = null; + FileNotFoundException fnf = null; try { parser = new FileParse(file, sourceType); @@ -92,6 +96,14 @@ public class IdentifyFile { return identify(parser); } + } catch (FileNotFoundException e) + { + fnf = e; + emessage = "Could not find '" + file + "'"; + Console.error("Could not find '" + file + "'", e); + } catch (IOException e) + { + Console.error("Error whilst trying to read " + file, e); } catch (Exception e) { Console.error("Error whilst identifying " + file, e); @@ -101,6 +113,10 @@ public class IdentifyFile { throw new FileFormatException(parser.errormessage); } + if (fnf != null) + { + throw (fnf); + } throw new FileFormatException(emessage); } @@ -134,6 +150,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 @@ -188,6 +205,10 @@ public class IdentifyFile reply = FileFormat.ScoreMatrix; break; } + if (data.startsWith(XMLHEADER) && !lineswereskipped) + { + isXml = true; + } if (data.startsWith("LOCUS")) { reply = FileFormat.GenBank; @@ -346,6 +367,12 @@ public class IdentifyFile reply = FileFormat.Rnaml; break; } + if (isXml && data.contains( + "")) + { + reply = FileFormat.FeatureSettings; + break; + } } if ((data.length() < 1) || (data.indexOf("#") == 0)) @@ -481,6 +508,10 @@ public class IdentifyFile try { type = ider.identify(args[i], DataSourceType.FILE); + } catch (FileNotFoundException e) + { + Console.error(String.format("Error '%s' fetching file %s", args[i], + e.getMessage())); } catch (FileFormatException e) { Console.error(