- java.lang.Object
-
- io.netty5.handler.codec.compression.SnappyDecompressor
-
- All Implemented Interfaces:
Decompressor,AutoCloseable
public final class SnappyDecompressor extends Object implements Decompressor
Uncompresses aBufferencoded with the Snappy framing format. See Snappy framing format. Note that by default, validation of the checksum header in each chunk is DISABLED for performance improvements. If performance is less of an issue, or if you would prefer the safety that checksum validation brings, please use theSnappyDecompressor(boolean)constructor with the argument set totrue.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close the decompressor.Bufferdecompress(Buffer in, BufferAllocator allocator)This method will read from the inputBufferand decompress into a newBufferthat will be allocated (if needed) from theBufferAllocator.booleanisClosed()Returntrueif the decompressor was closed,falseotherwise.booleanisFinished()Returns true if the decompressor was finish.static Supplier<SnappyDecompressor>newFactory()Creates a new snappy decompressor factory with validation of checksums turned OFF.static Supplier<SnappyDecompressor>newFactory(boolean validateChecksums)Creates a new snappy decompressor factory with validation of checksums as specified.
-
-
-
Method Detail
-
newFactory
public static Supplier<SnappyDecompressor> newFactory()
Creates a new snappy decompressor factory with validation of checksums turned OFF. To turn checksum validation on, please use the alternateSnappyDecompressor(boolean)constructor.- Returns:
- the factory.
-
newFactory
public static Supplier<SnappyDecompressor> newFactory(boolean validateChecksums)
Creates a new snappy decompressor factory with validation of checksums as specified.- Parameters:
validateChecksums- If true, the checksum field will be validated against the actual uncompressed data, and if the checksums do not match, a suitableDecompressionExceptionwill be thrown- Returns:
- the factory.
-
decompress
public Buffer decompress(Buffer in, BufferAllocator allocator) throws DecompressionException
Description copied from interface:DecompressorThis method will read from the inputBufferand decompress into a newBufferthat will be allocated (if needed) from theBufferAllocator. If there is not enough readable data in theBufferto process it will returnnull. This method should be called in a loop as long: Otherwise this method should be called again once there is more data in the input buffer.Decompressor.isFinished()isfalse- something was read from the
input- something was returned
- Specified by:
decompressin interfaceDecompressor- Parameters:
in- theBufferthat contains the data to be decompressed.allocator- theBufferAllocatorthat is used to allocate a new buffer (if needed) to write the decompressed bytes too.- Returns:
- the
Bufferthat contains the decompressed data. The caller of this method takes ownership of the buffer. The return value will benullif there is not enough data readable in the input to make any progress. In this case the user should call it again once there is more data ready to be consumed. - Throws:
DecompressionException- thrown if an decompression error was encountered or the decompressor was closed before.
-
isFinished
public boolean isFinished()
Description copied from interface:DecompressorReturns true if the decompressor was finish. This might be because the decompressor was explicitly closed or the end of the compressed stream was detected.- Specified by:
isFinishedin interfaceDecompressor- Returns:
trueif the decompressor is done with decompressing the stream.
-
isClosed
public boolean isClosed()
Description copied from interface:DecompressorReturntrueif the decompressor was closed,falseotherwise.- Specified by:
isClosedin interfaceDecompressor- Returns:
- if
Decompressor.close()was called.
-
close
public void close()
Description copied from interface:DecompressorClose the decompressor. After this method was calledDecompressor.isFinished()will returntrueas well and it is not allowed to callDecompressor.decompress(Buffer, BufferAllocator)anymore.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceDecompressor
-
-