net.spy.memcached.transcoders
Class BaseSerializingTranscoder

java.lang.Object
  extended by net.spy.memcached.compat.SpyObject
      extended by net.spy.memcached.transcoders.BaseSerializingTranscoder
Direct Known Subclasses:
SerializingTranscoder, WhalinTranscoder, WhalinV1Transcoder

public abstract class BaseSerializingTranscoder
extends SpyObject

Base class for any transcoders that may want to work with serialized or compressed data.


Field Summary
protected  String charset
           
protected  int compressionThreshold
           
static int DEFAULT_COMPRESSION_THRESHOLD
          Default compression threshold value.
 
Constructor Summary
BaseSerializingTranscoder(int max)
          Initialize a serializing transcoder with the given maximum data size.
 
Method Summary
 boolean asyncDecode(CachedData d)
           
protected  byte[] compress(byte[] in)
          Compress the given array of bytes.
protected  String decodeString(byte[] data)
          Decode the string with the current character set.
protected  byte[] decompress(byte[] in)
          Decompress the given array of bytes.
protected  Object deserialize(byte[] in)
          Get the object represented by the given serialized bytes.
protected  byte[] encodeString(String in)
          Encode a string into the current character set.
 int getMaxSize()
           
protected  byte[] serialize(Object o)
          Get the bytes representing the given serialized object.
 void setCharset(String to)
          Set the character set for string value transcoding (defaults to UTF-8).
 void setCompressionThreshold(int to)
          Set the compression threshold to the given number of bytes.
 
Methods inherited from class net.spy.memcached.compat.SpyObject
getLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_COMPRESSION_THRESHOLD

public static final int DEFAULT_COMPRESSION_THRESHOLD
Default compression threshold value.

See Also:
Constant Field Values

compressionThreshold

protected int compressionThreshold

charset

protected String charset
Constructor Detail

BaseSerializingTranscoder

public BaseSerializingTranscoder(int max)
Initialize a serializing transcoder with the given maximum data size.

Method Detail

asyncDecode

public boolean asyncDecode(CachedData d)

setCompressionThreshold

public void setCompressionThreshold(int to)
Set the compression threshold to the given number of bytes. This transcoder will attempt to compress any data being stored that's larger than this.

Parameters:
to - the number of bytes

setCharset

public void setCharset(String to)
Set the character set for string value transcoding (defaults to UTF-8).


serialize

protected byte[] serialize(Object o)
Get the bytes representing the given serialized object.


deserialize

protected Object deserialize(byte[] in)
Get the object represented by the given serialized bytes.


compress

protected byte[] compress(byte[] in)
Compress the given array of bytes.


decompress

protected byte[] decompress(byte[] in)
Decompress the given array of bytes.

Returns:
null if the bytes cannot be decompressed

decodeString

protected String decodeString(byte[] data)
Decode the string with the current character set.


encodeString

protected byte[] encodeString(String in)
Encode a string into the current character set.


getMaxSize

public int getMaxSize()