public static boolean isGzipFile(InputStream in) throws IOException {
  if (!in.markSupported()) {
    throw new IllegalArgumentException("Require a resetable stream");
  }
  in.mark(2);
  try {
    final byte[] b=new byte[2];
    IOUtils.readFully(in,b,0,2);
    final int magic=(((int)b[1] & 0xff) << 8) | ((int)b[0] & 0xff);
    return magic == GZIPInputStream.GZIP_MAGIC;
  }
  finally {
    in.reset();
  }
}

public static boolean isGzipFile ( InputStream in ) throws IOException { if ( ! in . markSupported ( ) ) { throw new IllegalArgumentException ( "Require a resetable stream" ) ; } in . mark ( 2 ) ; try { final byte [ ] b = new byte [ 2 ] ; IOUtils . readFully ( in , b , 0 , 2 ) ; final int magic = ( ( ( int ) b [ 1 ] & 0xff ) << 8 ) | ( ( int ) b [ 0 ] & 0xff ) ; return magic == GZIPInputStream . GZIP_MAGIC ; } finally { in . reset ( ) ; } }
checks first 2 bytes for presence of gzip identifier . stream is then reset to position it was in before being passed to this method .
