From 5143ca2a7f20619e9f9fb9350fe4683719522016 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Thu, 7 Nov 2013 13:43:30 +0000 Subject: [PATCH] JAL-1286 check if local file ends with .gz and opens as a gzip stream --- src/jalview/io/FileParse.java | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) 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) { -- 1.7.10.2