Package org.apache.hadoop.io.compress
Interface Compressor
@Public
@Evolving
public interface Compressor
Specification of a stream-based 'compressor' which can be
plugged into a
CompressionOutputStream to compress data.
This is modelled after Deflater-
Method Summary
Modifier and TypeMethodDescriptionintcompress(byte[] b, int off, int len) Fills specified buffer with compressed data.voidend()Closes the compressor and discards any unprocessed input.voidfinish()When called, indicates that compression should end with the current contents of the input buffer.booleanfinished()Returns true if the end of the compressed data output stream has been reached.longReturn number of uncompressed bytes input so far.longReturn number of compressed bytes output so far.booleanReturns true if the input data buffer is empty and #setInput() should be called to provide more input.voidreinit(Configuration conf) Prepare the compressor to be used in a new stream with settings defined in the given Configurationvoidreset()Resets compressor so that a new set of input data can be processed.voidsetDictionary(byte[] b, int off, int len) Sets preset dictionary for compression.voidsetInput(byte[] b, int off, int len) Sets input data for compression.
-
Method Details
-
setInput
void setInput(byte[] b, int off, int len) Sets input data for compression. This should be called whenever #needsInput() returnstrueindicating that more input data is required.- Parameters:
b- Input dataoff- Start offsetlen- Length
-
needsInput
boolean needsInput()Returns true if the input data buffer is empty and #setInput() should be called to provide more input.- Returns:
trueif the input data buffer is empty and #setInput() should be called in order to provide more input.
-
setDictionary
void setDictionary(byte[] b, int off, int len) Sets preset dictionary for compression. A preset dictionary is used when the history buffer can be predetermined.- Parameters:
b- Dictionary data bytesoff- Start offsetlen- Length
-
getBytesRead
long getBytesRead()Return number of uncompressed bytes input so far.- Returns:
- bytes read.
-
getBytesWritten
long getBytesWritten()Return number of compressed bytes output so far.- Returns:
- bytes written.
-
finish
void finish()When called, indicates that compression should end with the current contents of the input buffer. -
finished
boolean finished()Returns true if the end of the compressed data output stream has been reached.- Returns:
trueif the end of the compressed data output stream has been reached.
-
compress
Fills specified buffer with compressed data. Returns actual number of bytes of compressed data. A return value of 0 indicates that needsInput() should be called in order to determine if more input data is required.- Parameters:
b- Buffer for the compressed dataoff- Start offset of the datalen- Size of the buffer- Returns:
- The actual number of bytes of compressed data.
- Throws:
IOException- raised on errors performing I/O.
-
reset
void reset()Resets compressor so that a new set of input data can be processed. -
end
void end()Closes the compressor and discards any unprocessed input. -
reinit
Prepare the compressor to be used in a new stream with settings defined in the given Configuration- Parameters:
conf- Configuration from which new setting are fetched
-