X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FFileParse.java;h=d3a6ba936b86c3f65feaa7bc165995e4e31575ae;hb=7fe4dbd0f30dd29c51daaf291d3710af7b1c88b9;hp=3726c6bd5b17699b8d5438572f46077eb1c7530a;hpb=f60987555392a60449a37fe08a0f53003c26937b;p=jalview.git diff --git a/src/jalview/io/FileParse.java b/src/jalview/io/FileParse.java index 3726c6b..d3a6ba9 100755 --- a/src/jalview/io/FileParse.java +++ b/src/jalview/io/FileParse.java @@ -41,7 +41,7 @@ import jalview.api.AlignExportSettingsI; import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.api.FeatureSettingsModelI; -import jalview.bin.Cache; +import jalview.bin.Console; import jalview.util.MessageManager; import jalview.util.Platform; @@ -219,24 +219,29 @@ public class FileParse * @param bytes * - at least two bytes * @return - * @throws IOException + * @throws IOException */ public static boolean isGzipStream(InputStream input) throws IOException { if (!input.markSupported()) { - Cache.log.error("FileParse.izGzipStream: input stream must support mark/reset"); + Console.error( + "FileParse.izGzipStream: input stream must support mark/reset"); return false; } input.mark(4); - byte[] bytes = { (byte) input.read(), (byte) input.read() }; // input.readNBytes(2); + + // get first 2 bytes or return false + byte[] bytes = new byte[2]; + int read = input.read(bytes); input.reset(); - if (bytes.length == 2) + if (read != bytes.length) { - int header = (bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00); - return (GZIPInputStream.GZIP_MAGIC == header); + return false; } - return false; + + int header = (bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00); + return (GZIPInputStream.GZIP_MAGIC == header); } /** @@ -338,7 +343,7 @@ public class FileParse } String encoding = _conn.getContentEncoding(); String contentType = _conn.getContentType(); - boolean isgzipped = "application/x-gzip".equalsIgnoreCase(contentType) + boolean isgzipped = "application/x-gzip".equalsIgnoreCase(contentType) || contentType.endsWith("gzip") || "gzip".equals(encoding); Exception e = null; InputStream inputStream = _conn.getInputStream();