JAL-1807
[jalview.git] / src / jalview / io / IdentifyFile.java
index beb1385..14848c7 100755 (executable)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2b1)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  *
  * This file is part of Jalview.
  *
@@ -20,6 +20,9 @@
  */
 package jalview.io;
 
+import jalview.jsdev.Constants;
+import jalview.jsdev.GenericFileAdapter;
+
 import java.io.IOException;
 
 /**
@@ -30,6 +33,8 @@ import java.io.IOException;
  */
 public class IdentifyFile
 {
+  public static final String GFF3File = "GFF v2 or v3";
+
   /**
    * Identify a datasource's file content.
    *
@@ -96,7 +101,7 @@ public class IdentifyFile
       }
       while ((data = source.nextLine()) != null)
       {
-        length += data.length();
+        length += data.trim().length();
         if (!lineswereskipped)
         {
           for (int i = 0; !isBinary && i < data.length(); i++)
@@ -130,20 +135,34 @@ public class IdentifyFile
         }
         data = data.toUpperCase();
 
-        if ((data.indexOf("# STOCKHOLM") > -1))
+        if (data.startsWith("##GFF-VERSION"))
+        {
+          reply = GFF3File;
+          break;
+        }
+        if (data.indexOf("# STOCKHOLM") > -1)
         {
           reply = "STH";
-
+          break;
+        }
+        // if (data.matches("<(\"[^\"]*\"|'[^']*'|[^'\">])*>"))
+        if (data.matches("<HTML(\"[^\"]*\"|'[^']*'|[^'\">])*>")) // BH was (?i)rnaml, but JavaScript regex does not support (?i); data is already upper case
+        {
+          reply = Constants.Html_FILE_DESC;
           break;
         }
 
-        if ((data.indexOf("<") > -1))
+        if (data.matches("<RNAML (\"[^\"]*\"|'[^']*'|[^'\">])*>")) // BH was (?i)rnaml, but JavaScript regex does not support (?i); data is already upper case
         {
           reply = "RNAML";
-
           break;
         }
 
+         if (data.indexOf("{\"") > -1)
+         {
+         reply = Constants.JSON_FILE_DESC;
+         break;
+         }
         if ((data.length() < 1) || (data.indexOf("#") == 0))
         {
           lineswereskipped = true;
@@ -271,10 +290,11 @@ public class IdentifyFile
         }
         else if (data.matches("\\s*\\d+\\s+\\d+\\s*"))
         {
-          reply = PhylipFile.FILE_DESC;
+          reply = Constants.Phylip_FILE_DESC;
           break;
         }
 
+
         /*
          * // TODO comment out SimpleBLAST identification for Jalview 2.4.1 else
          * if (!lineswereskipped && data.indexOf("BLAST")<4) { reply =
@@ -318,8 +338,14 @@ public class IdentifyFile
     return reply;
   }
 
+  /**
+   * @j2sIgnore
+   * 
+   * @param args
+   */
   public static void main(String[] args)
   {
+
     for (int i = 0; args != null && i < args.length; i++)
     {
       IdentifyFile ider = new IdentifyFile();