X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FFileParse.java;h=2ff0d2715ca92907704efb0107d61295b728a2ac;hb=3975a73e927fe1adb8f3411f22c10a3e5e74ec73;hp=3726c6bd5b17699b8d5438572f46077eb1c7530a;hpb=f60987555392a60449a37fe08a0f53003c26937b;p=jalview.git diff --git a/src/jalview/io/FileParse.java b/src/jalview/io/FileParse.java index 3726c6b..2ff0d27 100755 --- a/src/jalview/io/FileParse.java +++ b/src/jalview/io/FileParse.java @@ -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"); + 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); + + // 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); } /**