From: Ben Soares Date: Thu, 20 Aug 2020 13:55:50 +0000 (+0100) Subject: JAL-2656 better read of (potential) gzip magic bytes X-Git-Tag: Develop-2_11_2_0-d20201215~24^2~7^2^2~2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=b15eb801bc371fb2b7e147aa4ca90cbfb19899cf;p=jalview.git JAL-2656 better read of (potential) gzip magic bytes --- diff --git a/src/jalview/io/FileParse.java b/src/jalview/io/FileParse.java index 3726c6b..d986dc5 100755 --- a/src/jalview/io/FileParse.java +++ b/src/jalview/io/FileParse.java @@ -219,18 +219,24 @@ 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"); + Cache.log.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); + byte[] bytes = new byte[2]; // input.readNBytes(2); + int read = input.read(bytes); input.reset(); + if (read != bytes.length) + { + return false; + } if (bytes.length == 2) { int header = (bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00);