Java GZip InputStream Check isGZip(BufferedInputStream instream)

Here you can find the source of isGZip(BufferedInputStream instream)

Description

Test for GZIP stream signature.

License

Open Source License

Parameter

Parameter Description
instream the BufferedInputStream to test.

Return

true if input stream is gzip.

Declaration

public static boolean isGZip(BufferedInputStream instream) 

Method Source Code

//package com.java2s;
import java.io.BufferedInputStream;

public class Main {
    /**/*from   w  w  w .jav a2  s.c  o  m*/
     * Test for GZIP stream signature.
     *
     * @param instream the BufferedInputStream to test.
     * @return true if input stream is gzip.
     */
    public static boolean isGZip(BufferedInputStream instream) {
        instream.mark(2);
        byte[] b = new byte[2];

        try {
            instream.read(b, 0, 2);
        } catch (Exception ex) {
            throw new RuntimeException("Couldn't read header from stream ",
                    ex);
        }

        try {
            instream.reset();
        } catch (Exception ex) {
            throw new RuntimeException("Couldn't reset stream ", ex);
        }

        return (b[0] == 31 && b[1] == -117);
    }
}

Related

  1. isGZIPCompressed(InputStream in)
  2. isGZipped(InputStream in)
  3. isGZipped(InputStream in)
  4. isGzipStm(InputStream in)