org.apache.hadoop.io.compress.snappy
Class SnappyCompressor

java.lang.Object
  extended by org.apache.hadoop.io.compress.snappy.SnappyCompressor
All Implemented Interfaces:
Compressor

public class SnappyCompressor
extends Object
implements Compressor

A Compressor based on the snappy compression algorithm. http://code.google.com/p/snappy/


Constructor Summary
SnappyCompressor()
          Creates a new compressor with the default buffer size.
SnappyCompressor(int directBufferSize)
          Creates a new compressor.
 
Method Summary
 int compress(byte[] b, int off, int len)
          Fills specified buffer with compressed data.
 void end()
          Closes the compressor and discards any unprocessed input.
 void finish()
          When called, indicates that compression should end with the current contents of the input buffer.
 boolean finished()
          Returns true if the end of the compressed data output stream has been reached.
 long getBytesRead()
          Return number of bytes given to this compressor since last reset.
 long getBytesWritten()
          Return number of bytes consumed by callers of compress since last reset.
 boolean needsInput()
          Returns true if the input data buffer is empty and #setInput() should be called to provide more input.
 void reinit(Configuration conf)
          Prepare the compressor to be used in a new stream with settings defined in the given Configuration
 void reset()
          Resets compressor so that a new set of input data can be processed.
 void setDictionary(byte[] b, int off, int len)
          Does nothing.
 void setInput(byte[] b, int off, int len)
          Sets input data for compression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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 Detail

setInput

public void setInput(byte[] b,
                     int off,
                     int len)
Sets input data for compression. This should be called whenever #needsInput() returns true indicating that more input data is required.

Specified by:
setInput in interface Compressor
Parameters:
b - Input data
off - Start offset
len - Length

setDictionary

public void setDictionary(byte[] b,
                          int off,
                          int len)
Does nothing.

Specified by:
setDictionary in interface Compressor
Parameters:
b - Dictionary data bytes
off - Start offset
len - 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:
needsInput in interface Compressor
Returns:
true if 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:
finish in interface Compressor

finished

public boolean finished()
Returns true if the end of the compressed data output stream has been reached.

Specified by:
finished in interface Compressor
Returns:
true if the end of the compressed data output stream has been reached.

compress

public int compress(byte[] b,
                    int off,
                    int len)
             throws IOException
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:
compress in interface Compressor
Parameters:
b - Buffer for the compressed data
off - Start offset of the data
len - Size of the buffer
Returns:
The actual number of bytes of compressed data.
Throws:
IOException

reset

public void reset()
Resets compressor so that a new set of input data can be processed.

Specified by:
reset in interface Compressor

reinit

public void reinit(Configuration conf)
Prepare the compressor to be used in a new stream with settings defined in the given Configuration

Specified by:
reinit in interface Compressor
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:
getBytesRead in interface Compressor

getBytesWritten

public long getBytesWritten()
Return number of bytes consumed by callers of compress since last reset.

Specified by:
getBytesWritten in interface Compressor

end

public void end()
Closes the compressor and discards any unprocessed input.

Specified by:
end in interface Compressor


Copyright © 2009 The Apache Software Foundation