From: Jim Procter Date: Thu, 7 Nov 2013 13:43:30 +0000 (+0000) Subject: JAL-1286 check if local file ends with .gz and opens as a gzip stream X-Git-Tag: Jalview_2_9~215^2~1 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=5143ca2a7f20619e9f9fb9350fe4683719522016;p=jalview.git JAL-1286 check if local file ends with .gz and opens as a gzip stream --- diff --git a/src/jalview/io/FileParse.java b/src/jalview/io/FileParse.java index f9440fa..bb52ec2 100755 --- a/src/jalview/io/FileParse.java +++ b/src/jalview/io/FileParse.java @@ -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) {