com.bigdata.io.compression
Class RecordCompressor

java.lang.Object
  extended by com.bigdata.io.compression.RecordCompressor
All Implemented Interfaces:
IRecordCompressor, Externalizable, Serializable

public class RecordCompressor
extends Object
implements Externalizable, IRecordCompressor

Bulk data (de-)compressor used for leaves in IndexSegments. The compression and decompression operations of a given RecordCompressor reuse a shared instance buffer. Any decompression result is valid only until the next compression or decompression operation performed by that RecordCompressor. When used in a single-threaded context this reduces allocation while maximizing the opportunity for bulk transfers.

This class is NOT thread-safe.

Version:
$Id: RecordCompressor.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson
See Also:
Serialized Form

Constructor Summary
RecordCompressor()
          De-serialization constructor.
RecordCompressor(int level)
          Create a record compressor.
 
Method Summary
 void compress(byte[] bytes, int off, int len, OutputStream os)
          Compresses data onto the output stream.
 void compress(byte[] bytes, OutputStream os)
          Compresses data onto the output stream.
 void compress(ByteBuffer bin, OutputStream os)
          Compresses data onto the output stream.
 ByteBuffer decompress(byte[] bin)
          Decompress a byte[] containing the record and return the uncompressed state.
 ByteBuffer decompress(ByteBuffer bin)
          Decompress a ByteBuffer containing the record and return the uncompressed state.
protected  ByteBuffer decompress(InflaterInputStream iis)
          This decompresses data into a shared instance byte[].
 void readExternal(ObjectInput in)
           
 String toString()
           
 void writeExternal(ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RecordCompressor

public RecordCompressor(int level)
Create a record compressor.

Parameters:
level - The compression level.
See Also:
Deflater.BEST_SPEED, Deflater.BEST_COMPRESSION

RecordCompressor

public RecordCompressor()
De-serialization constructor.

Method Detail

toString

public String toString()
Overrides:
toString in class Object

compress

public void compress(ByteBuffer bin,
                     OutputStream os)
Description copied from interface: IRecordCompressor
Compresses data onto the output stream.

Specified by:
compress in interface IRecordCompressor
Parameters:
bin - The data. The data from the position to the limit will be compressed. The position will be advanced to the limit as a side effect.
os - The stream onto which the compressed data are written.

compress

public void compress(byte[] bytes,
                     OutputStream os)
Description copied from interface: IRecordCompressor
Compresses data onto the output stream.

Specified by:
compress in interface IRecordCompressor
Parameters:
bytes - The data.
os - The stream onto which the compressed data are written.

compress

public void compress(byte[] bytes,
                     int off,
                     int len,
                     OutputStream os)
Description copied from interface: IRecordCompressor
Compresses data onto the output stream.

Specified by:
compress in interface IRecordCompressor
Parameters:
bytes - The source data.
off - The offset of the first source byte that will be compressed onto the output stream.
len - The #of source bytes that will be compressed onto the output stream.
os - The stream onto which the compressed data are written.

decompress

public ByteBuffer decompress(ByteBuffer bin)
Description copied from interface: IRecordCompressor
Decompress a ByteBuffer containing the record and return the uncompressed state.

Specified by:
decompress in interface IRecordCompressor
Parameters:
bin - The compressed data.
Returns:
A view onto a shared buffer. The data between position() and limit() are the decompressed data. The contents of this buffer are valid only until the next compression or decompression request.

decompress

public ByteBuffer decompress(byte[] bin)
Description copied from interface: IRecordCompressor
Decompress a byte[] containing the record and return the uncompressed state.

Specified by:
decompress in interface IRecordCompressor
Parameters:
bin - The compressed data.
Returns:
A read-only view onto a shared buffer. The data between position() and limit() are the decompressed data. The contents of this buffer are valid only until the next compression or decompression request. The position will be zero. The limit will be the #of decompressed bytes.

decompress

protected ByteBuffer decompress(InflaterInputStream iis)
This decompresses data into a shared instance byte[]. If the byte[] runs out of capacity then a new byte[] is allocated with twice the capacity, the data is copied into new byte[], and decompression continues. The shared instance byte[] is then returned to the caller. This approach is suited to single-threaded processes that achieve a suitable buffer size and then perform zero allocations thereafter.

Returns:
A read-only view onto a shared buffer. The data between position() and limit() are the decompressed data. The contents of this buffer are valid only until the next compression or decompression request. The position will be zero. The limit will be the #of decompressed bytes.

readExternal

public void readExternal(ObjectInput in)
                  throws IOException,
                         ClassNotFoundException
Specified by:
readExternal in interface Externalizable
Throws:
IOException
ClassNotFoundException

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Specified by:
writeExternal in interface Externalizable
Throws:
IOException


Copyright © 2006-2012 SYSTAP, LLC. All Rights Reserved.