Java tutorial
//package com.java2s; import java.io.IOException; import java.io.PushbackInputStream; import java.util.zip.GZIPInputStream; public class Main { /** * Checks the InputStream if it contains GZIP compressed data * * @param inputStream InputStream to be checked * @return true or false if the stream contains GZIP compressed data * @throws java.io.IOException */ public static boolean isInputStreamGZIPCompressed(final PushbackInputStream inputStream) throws IOException { if (inputStream == null) return false; byte[] signature = new byte[2]; int readStatus = inputStream.read(signature); inputStream.unread(signature); int streamHeader = ((int) signature[0] & 0xff) | ((signature[1] << 8) & 0xff00); return readStatus == 2 && GZIPInputStream.GZIP_MAGIC == streamHeader; } }