- private static boolean isGzipStream(byte[] bytes) {
- int head = ((int) bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00);
- return (GZIPInputStream.GZIP_MAGIC == head);
+ public static boolean isGzipStream(InputStream input) throws IOException
+ {
+ if (!input.markSupported())
+ {
+ Console.error(
+ "FileParse.izGzipStream: input stream must support mark/reset");
+ return false;
+ }
+ input.mark(4);
+
+ // get first 2 bytes or return false
+ byte[] bytes = new byte[2];
+ int read = input.read(bytes);
+ input.reset();
+ if (read != bytes.length)
+ {
+ return false;
+ }
+
+ int header = (bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00);
+ return (GZIPInputStream.GZIP_MAGIC == header);