JAL-1286 check if local file ends with .gz and opens as a gzip stream
authorJim Procter <jprocter@compbio.dundee.ac.uk>
Thu, 7 Nov 2013 13:43:30 +0000 (13:43 +0000)
committerJim Procter <jprocter@compbio.dundee.ac.uk>
Thu, 7 Nov 2013 13:43:30 +0000 (13:43 +0000)
src/jalview/io/FileParse.java

index f9440fa..bb52ec2 100755 (executable)
@@ -142,12 +142,35 @@ public class FileParse
     }
     if (!error)
     {
+      if (fileStr.toLowerCase().endsWith(".gz"))
+      {
+        try
+        {
+          dataIn = tryAsGzipSource(new FileInputStream(fileStr));
+          dataName = fileStr;
+          return error;
+        } catch (Exception x)
+        {
+          warningMessage = "Failed  to resolve as a GZ stream ("
+                  + x.getMessage() + ")";
+          x.printStackTrace();
+        }
+        ;
+      }
+      
       dataIn = new BufferedReader(new FileReader(fileStr));
       dataName = fileStr;
     }
     return error;
   }
-
+  private BufferedReader tryAsGzipSource(InputStream inputStream) throws Exception
+  {
+    BufferedReader inData = new BufferedReader(new InputStreamReader(new GZIPInputStream(inputStream)));
+    inData.mark(2048);
+    inData.read();
+    inData.reset();
+    return inData;
+  }
   private boolean checkURLSource(String fileStr) throws IOException,
           MalformedURLException
   {
@@ -156,14 +179,10 @@ public class FileParse
     //
     // GZIPInputStream code borrowed from Aquaria (soon to be open sourced) via Kenny Sabir
     Exception e=null;
-    if (fileStr.endsWith(".gz")) {
+    if (fileStr.toLowerCase().endsWith(".gz")) {
       try {
           InputStream inputStream = url.openStream();
-          dataIn = new BufferedReader(new InputStreamReader(new GZIPInputStream(inputStream)));
-          dataIn.mark(2048);
-          dataIn.read();
-          dataIn.reset();
-          
+          dataIn = tryAsGzipSource(inputStream);
           dataName = fileStr;
           return false;
       } catch (Exception ex) {