JAL-3949 Complete new abstracted logging framework in jalview.log. Updated log calls...
[jalview.git] / src / jalview / io / FileParse.java
index 3726c6b..1306f43 100755 (executable)
@@ -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.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);
   }
 
   /**