Search in sources :

Example 1 with ZstdInputStream

use of com.github.luben.zstd.ZstdInputStream in project netty by netty.

the class ZstdEncoderTest method decompress.

@Override
protected ByteBuf decompress(ByteBuf compressed, int originalLength) throws Exception {
    InputStream is = new ByteBufInputStream(compressed, true);
    ZstdInputStream zstdIs = null;
    byte[] decompressed = new byte[originalLength];
    try {
        zstdIs = new ZstdInputStream(is);
        int remaining = originalLength;
        while (remaining > 0) {
            int read = zstdIs.read(decompressed, originalLength - remaining, remaining);
            if (read > 0) {
                remaining -= read;
            } else {
                break;
            }
        }
        assertEquals(-1, zstdIs.read());
    } finally {
        if (zstdIs != null) {
            zstdIs.close();
        } else {
            is.close();
        }
    }
    return Unpooled.wrappedBuffer(decompressed);
}
Also used : ZstdInputStream(com.github.luben.zstd.ZstdInputStream) ZstdInputStream(com.github.luben.zstd.ZstdInputStream) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) InputStream(java.io.InputStream) ByteBufInputStream(io.netty.buffer.ByteBufInputStream)

Aggregations

ZstdInputStream (com.github.luben.zstd.ZstdInputStream)1 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)1 InputStream (java.io.InputStream)1