Search in sources :

Example 1 with LzmaInputStream

use of lzma.streams.LzmaInputStream in project netty by netty.

the class LzmaFrameEncoderTest method decompress.

@Override
protected ByteBuf decompress(ByteBuf compressed, int originalLength) throws Exception {
    InputStream is = new ByteBufInputStream(compressed, true);
    LzmaInputStream lzmaIs = null;
    byte[] decompressed = new byte[originalLength];
    try {
        lzmaIs = new LzmaInputStream(is, new Decoder());
        int remaining = originalLength;
        while (remaining > 0) {
            int read = lzmaIs.read(decompressed, originalLength - remaining, remaining);
            if (read > 0) {
                remaining -= read;
            } else {
                break;
            }
        }
        assertEquals(-1, lzmaIs.read());
    } finally {
        if (lzmaIs != null) {
            lzmaIs.close();
        }
        // https://github.com/jponge/lzma-java/issues/14
        if (is != null) {
            is.close();
        }
    }
    return Unpooled.wrappedBuffer(decompressed);
}
Also used : LzmaInputStream(lzma.streams.LzmaInputStream) LzmaInputStream(lzma.streams.LzmaInputStream) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) InputStream(java.io.InputStream) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) Decoder(lzma.sdk.lzma.Decoder)

Aggregations

ByteBufInputStream (io.netty.buffer.ByteBufInputStream)1 InputStream (java.io.InputStream)1 Decoder (lzma.sdk.lzma.Decoder)1 LzmaInputStream (lzma.streams.LzmaInputStream)1