JAL-4409 Allow more URI schemes (e.g. file) to be opened in Jalview
[jalview.git] / src / jalview / io / IdentifyFile.java
index 00e2872..8251c22 100755 (executable)
@@ -21,6 +21,7 @@
 package jalview.io;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.Locale;
 
@@ -38,7 +39,7 @@ public class IdentifyFile
   private static final String XMLHEADER = "<?XML VERSION=\"1.0\" ENCODING=\"UTF-8\" STANDALONE=\"YES\"?>";
 
   public FileFormatI identify(Object file, DataSourceType protocol)
-          throws FileFormatException
+          throws FileFormatException, FileNotFoundException
   {
     // BH 2018
     return (file instanceof File ? identify((File) file, protocol)
@@ -83,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);
@@ -94,6 +96,11 @@ 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);
@@ -106,6 +113,10 @@ public class IdentifyFile
     {
       throw new FileFormatException(parser.errormessage);
     }
+    if (fnf != null)
+    {
+      throw (fnf);
+    }
     throw new FileFormatException(emessage);
   }
 
@@ -497,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(