Class SnappyCompressor
java.lang.Object
org.apache.hadoop.io.compress.snappy.SnappyCompressor
- All Implemented Interfaces:
Compressor
A
Compressor based on the snappy compression algorithm.
http://code.google.com/p/snappy/-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new compressor with the default buffer size.SnappyCompressor(int directBufferSize) Creates a new compressor. -
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 bytes given to this compressor since last reset.longReturn number of bytes consumed by callers of compress since last reset.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) Does nothing.voidsetInput(byte[] b, int off, int len) Sets input data for compression.
-
Constructor Details
-
SnappyCompressor
public SnappyCompressor(int directBufferSize) Creates a new compressor.- Parameters:
directBufferSize- size of the direct buffer to be used.
-
SnappyCompressor
public SnappyCompressor()Creates a new compressor with the default buffer size.
-
-
Method Details
-
setInput
public 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.- Specified by:
setInputin interfaceCompressor- Parameters:
b- Input dataoff- Start offsetlen- Length
-
setDictionary
public void setDictionary(byte[] b, int off, int len) Does nothing.- Specified by:
setDictionaryin interfaceCompressor- Parameters:
b- Dictionary data bytesoff- Start offsetlen- Length
-
needsInput
public boolean needsInput()Returns true if the input data buffer is empty and #setInput() should be called to provide more input.- Specified by:
needsInputin interfaceCompressor- Returns:
trueif the input data buffer is empty and #setInput() should be called in order to provide more input.
-
finish
public void finish()When called, indicates that compression should end with the current contents of the input buffer.- Specified by:
finishin interfaceCompressor
-
finished
public boolean finished()Returns true if the end of the compressed data output stream has been reached.- Specified by:
finishedin interfaceCompressor- 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.- Specified by:
compressin interfaceCompressor- 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
public void reset()Resets compressor so that a new set of input data can be processed.- Specified by:
resetin interfaceCompressor
-
reinit
Prepare the compressor to be used in a new stream with settings defined in the given Configuration- Specified by:
reinitin interfaceCompressor- Parameters:
conf- Configuration from which new setting are fetched
-
getBytesRead
public long getBytesRead()Return number of bytes given to this compressor since last reset.- Specified by:
getBytesReadin interfaceCompressor- Returns:
- bytes read.
-
getBytesWritten
public long getBytesWritten()Return number of bytes consumed by callers of compress since last reset.- Specified by:
getBytesWrittenin interfaceCompressor- Returns:
- bytes written.
-
end
public void end()Closes the compressor and discards any unprocessed input.- Specified by:
endin interfaceCompressor
-