-
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
BrotliCompressor
,Bzip2Compressor
,FastLzCompressor
,Lz4Compressor
,LzfCompressor
,LzmaCompressor
,SnappyCompressor
,ZlibCompressor
,ZstdCompressor
public interface Compressor extends AutoCloseable
Compressor that takes care of compress some input.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
close()
# Close the compressor.Buffer
compress(Buffer input, BufferAllocator allocator)
This method will read from the inputBuffer
and compress into a newBuffer
that will be allocated (if needed) from theBufferAllocator
.Buffer
finish(BufferAllocator allocator)
By calling this method we signal that the compression stream is marked as finish.boolean
isClosed()
Returntrue
if the decompressor was closed,false
otherwise.boolean
isFinished()
Returns true if the compressor was finished or closed.
-
-
-
Method Detail
-
compress
Buffer compress(Buffer input, BufferAllocator allocator) throws CompressionException
This method will read from the inputBuffer
and compress into a newBuffer
that will be allocated (if needed) from theBufferAllocator
. This method is expected to consume all data from the input but not take ownership. The caller is responsible to release the input buffer after this method returns.- Parameters:
input
- theBuffer
that contains the data to be compressed.allocator
- theBufferAllocator
that is used to allocate a new buffer (if needed) to write the compressed bytes too.- Returns:
- the
Buffer
that contains the compressed data. The caller of this method takes ownership of the buffer. The return value will never benull
. - Throws:
CompressionException
- thrown if an compression error was encountered or the compressor was closed already.
-
finish
Buffer finish(BufferAllocator allocator) throws CompressionException
By calling this method we signal that the compression stream is marked as finish. The returnedBuffer
might contain a "trailer" which marks the end of the stream.- Returns:
- the
Buffer
which represent the end of the compression stream, which might be empty if the compressor don't need a trailer to signal the end. The caller of this method takes ownership of the buffer. The return value will never benull
. - Throws:
CompressionException
- thrown if a compression error was encountered or the compressor was closed already.
-
isFinished
boolean isFinished()
Returns true if the compressor was finished or closed. This might happen because someone explicit calledfinish(BufferAllocator)
/close()
or the compressor implementation did decide to close itself due a compression error which can't be recovered. AfterisFinished()
returnstrue
thecompress(Buffer, BufferAllocator)
method will just return an empty buffer without consuming anything from its input buffer.- Returns:
true
if the compressor was marked as finished,false
otherwise.
-
isClosed
boolean isClosed()
Returntrue
if the decompressor was closed,false
otherwise.- Returns:
true
if the decompressor was closed,false
otherwise.
-
close
void close()
# Close the compressor. After this method was calledisFinished()
will returntrue
as well and it is not allowed to callcompress(Buffer, BufferAllocator)
orfinish(BufferAllocator)
anymore -- Specified by:
close
in interfaceAutoCloseable
-
-