JAL-3744 this obvious attempt to detect/gunzip file input for jalviewjs fails bug/JAL-3744_read_gzip_file_in_jalviewjs
authorBen Soares <b.soares@dundee.ac.uk>
Thu, 10 Sep 2020 14:27:08 +0000 (15:27 +0100)
committerBen Soares <b.soares@dundee.ac.uk>
Thu, 10 Sep 2020 14:27:08 +0000 (15:27 +0100)
src/jalview/io/FileParse.java

index 2ff0d27..8a48012 100755 (executable)
@@ -230,7 +230,7 @@ public class FileParse
       return false;
     }
     input.mark(4);
-    
+
     // get first 2 bytes or return false
     byte[] bytes = new byte[2];
     int read = input.read(bytes);
@@ -239,7 +239,7 @@ public class FileParse
     {
       return false;
     }
-    
+
     int header = (bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00);
     return (GZIPInputStream.GZIP_MAGIC == header);
   }
@@ -286,7 +286,9 @@ public class FileParse
     BufferedReader inData = new BufferedReader(
             new InputStreamReader(new GZIPInputStream(inputStream)));
     inData.mark(2048);
+    System.out.println("ABOUT TO inData.read()");
     inData.read();
+    System.out.println("ABOUT TO inData.reset()");
     inData.reset();
     return inData;
   }
@@ -448,8 +450,15 @@ public class FileParse
       {
         // this will be from JavaScript
         inFile = file;
-        dataIn = new BufferedReader(
-                new InputStreamReader(new ByteArrayInputStream(bytes)));
+        // dataIn = new BufferedReader(new InputStreamReader(new
+        // ByteArrayInputStream(bytes)));
+        try
+        {
+          dataIn = checkForGzipStream(new ByteArrayInputStream(bytes));
+        } catch (Exception e)
+        {
+          e.printStackTrace();
+        }
         dataName = fileStr;
       }
       else if (checkFileSource(fileStr))