private static FilterInputStream getStreamByMagicCode()

in java/client/src/main/java/org/apache/rocketmq/client/java/misc/Utilities.java [229:250]


    private static FilterInputStream getStreamByMagicCode(byte[] src, InputStream inputStream) throws IOException {
        // Automatically select the appropriate decompression algorithm according to magic code
        // GZIP magic code: 0x1F 0x8B
        // ZLIB magic code: 0x78
        // LZ4 magic code: 0x04 0x22 0x4D 0x18
        // ZSTD magic code: 0x28 0xB5 0x2F 0xFD
        FilterInputStream filterInputStream;
        if ((src[0] & 0xFF) == 0x1F && (src[1] & 0xFF) == 0x8B) {
            filterInputStream = new GZIPInputStream(inputStream);
        } else if ((src[0] & 0xFF) == 0x78) {
            filterInputStream = new InflaterInputStream(inputStream);
        } else if ((src[0] & 0xFF) == 0x04 && (src[1] & 0xFF) == 0x22 && (src[2] & 0xFF) == 0x4D
            && (src[3] & 0xFF) == 0x18) {
            filterInputStream = new LZ4FrameInputStream(inputStream);
        } else if (((src[0] & 0xFF) == 0x28 && (src[1] & 0xFF) == 0xB5 && (src[2] & 0xFF) == 0x2F
            && (src[3] & 0xFF) == 0xFD)) {
            filterInputStream = new ZstdInputStream(inputStream);
        } else {
            throw new IOException("Unknown compression format");
        }
        return filterInputStream;
    }