protected void readHeader()
            throws IOException
    {
        int readBytes = 0;
        while (readBytes < header.length) {
            int ret = in.read(header, readBytes, header.length - readBytes);
            if (ret == -1) {
                break;
            }
            readBytes += ret;
        }

        // Quick test of the header
        if (readBytes == 0) {
            // Snappy produces at least 1-byte result. So the empty input is not a valid input
            throw new SnappyIOException(SnappyErrorCode.EMPTY_INPUT, "Cannot decompress empty stream");
        }
        if (readBytes < header.length || !SnappyCodec.hasMagicHeaderPrefix(header)) {
            // do the default uncompression
            // (probably) compressed by Snappy.compress(byte[])
            readFully(header, readBytes);
            return;
        }
    }