Package net.spy.memcached.transcoders
Class BaseSerializingTranscoder
- java.lang.Object
-
- net.spy.memcached.compat.SpyObject
-
- 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
Fields Modifier and Type Field Description protected java.lang.Stringcharsetprotected intcompressionThresholdprivate static java.lang.StringDEFAULT_CHARSETstatic intDEFAULT_COMPRESSION_THRESHOLDDefault compression threshold value.private intmaxSize
-
Constructor Summary
Constructors Constructor Description BaseSerializingTranscoder(int max)Initialize a serializing transcoder with the given maximum data size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanasyncDecode(CachedData d)protected byte[]compress(byte[] in)Compress the given array of bytes.protected java.lang.StringdecodeString(byte[] data)Decode the string with the current character set.protected byte[]decompress(byte[] in)Decompress the given array of bytes.protected java.lang.Objectdeserialize(byte[] in)Get the object represented by the given serialized bytes.protected byte[]encodeString(java.lang.String in)Encode a string into the current character set.intgetMaxSize()protected byte[]serialize(java.lang.Object o)Get the bytes representing the given serialized object.voidsetCharset(java.lang.String to)Set the character set for string value transcoding (defaults to UTF-8).voidsetCompressionThreshold(int to)Set the compression threshold to the given number of bytes.
-
-
-
Field Detail
-
DEFAULT_COMPRESSION_THRESHOLD
public static final int DEFAULT_COMPRESSION_THRESHOLD
Default compression threshold value.- See Also:
- Constant Field Values
-
DEFAULT_CHARSET
private static final java.lang.String DEFAULT_CHARSET
- See Also:
- Constant Field Values
-
compressionThreshold
protected int compressionThreshold
-
charset
protected java.lang.String charset
-
maxSize
private final int maxSize
-
-
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(java.lang.String to)
Set the character set for string value transcoding (defaults to UTF-8).
-
serialize
protected byte[] serialize(java.lang.Object o)
Get the bytes representing the given serialized object.
-
deserialize
protected java.lang.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 java.lang.String decodeString(byte[] data)
Decode the string with the current character set.
-
encodeString
protected byte[] encodeString(java.lang.String in)
Encode a string into the current character set.
-
getMaxSize
public int getMaxSize()
-
-