com.esotericsoftware.kryo
Class Compressor

java.lang.Object
  extended by com.esotericsoftware.kryo.Serializer
      extended by com.esotericsoftware.kryo.Compressor
Direct Known Subclasses:
BlowfishCompressor, ByteArrayCompressor, DeltaCompressor

public abstract class Compressor
extends Serializer

Wraps another serializer in order to modify the bytes after they are serialized and before they are deserialized.

Author:
Nathan Sweet
See Also:
Kryo.register(Class, Serializer)

Field Summary
protected  int bufferSize
           
 
Constructor Summary
Compressor(Serializer serializer)
          Creates a compressor with compress and decompress set to true and bufferSize set to 2048.
Compressor(Serializer serializer, int bufferSize)
           
 
Method Summary
abstract  void compress(java.nio.ByteBuffer inputBuffer, java.lang.Object object, java.nio.ByteBuffer outputBuffer)
          The compressor should read the input buffer from the current position to the limit, compress the data, and put the result in the output buffer.
abstract  void decompress(java.nio.ByteBuffer inputBuffer, java.lang.Class type, java.nio.ByteBuffer outputBuffer)
          The compressor should read the input buffer from the current position to the limit, decompress the data, and put the result in the output buffer.
<T> T
readObjectData(java.nio.ByteBuffer buffer, java.lang.Class<T> type)
          Reads an object from the buffer.
 void setCompress(boolean compress)
          Sets whether the compressor will compress data after serialization.
 void setDecompress(boolean decompress)
          Sets whether the compressor will decompress data before serialization.
 void writeObjectData(java.nio.ByteBuffer buffer, java.lang.Object object)
          Writes the object to the buffer.
 
Methods inherited from class com.esotericsoftware.kryo.Serializer
isFinal, newInstance, readObject, setCanBeNull, writeObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bufferSize

protected final int bufferSize
Constructor Detail

Compressor

public Compressor(Serializer serializer)
Creates a compressor with compress and decompress set to true and bufferSize set to 2048.

Parameters:
serializer -

Compressor

public Compressor(Serializer serializer,
                  int bufferSize)
Parameters:
bufferSize - The maximum size in bytes of an object that can be read or written.
Method Detail

setCompress

public void setCompress(boolean compress)
Sets whether the compressor will compress data after serialization.


setDecompress

public void setDecompress(boolean decompress)
Sets whether the compressor will decompress data before serialization.


writeObjectData

public void writeObjectData(java.nio.ByteBuffer buffer,
                            java.lang.Object object)
Description copied from class: Serializer
Writes the object to the buffer.

Specified by:
writeObjectData in class Serializer
object - Cannot be null.

readObjectData

public <T> T readObjectData(java.nio.ByteBuffer buffer,
                            java.lang.Class<T> type)
Description copied from class: Serializer
Reads an object from the buffer.

Specified by:
readObjectData in class Serializer
Returns:
The deserialized object, never null.

compress

public abstract void compress(java.nio.ByteBuffer inputBuffer,
                              java.lang.Object object,
                              java.nio.ByteBuffer outputBuffer)
The compressor should read the input buffer from the current position to the limit, compress the data, and put the result in the output buffer.

Parameters:
outputBuffer - A non-direct buffer.

decompress

public abstract void decompress(java.nio.ByteBuffer inputBuffer,
                                java.lang.Class type,
                                java.nio.ByteBuffer outputBuffer)
The compressor should read the input buffer from the current position to the limit, decompress the data, and put the result in the output buffer.

Parameters:
outputBuffer - A non-direct buffer.


Copyright © 2011. All Rights Reserved.