public class DefaultCodec extends Object
JRedis
.
[TODO: document me!]Modifier and Type | Class and Description |
---|---|
static class |
DefaultCodec.Keys<K> |
Modifier and Type | Field and Description |
---|---|
static Charset |
SUPPORTED_CHARSET |
static String |
SUPPORTED_CHARSET_NAME |
Constructor and Description |
---|
DefaultCodec() |
Modifier and Type | Method and Description |
---|---|
static <T extends Serializable> |
decode(byte[] bytes)
This helper method will assume that the byte[] provided are the serialized
bytes obtainable for an instance of type T obtained from
ObjectOutputStream
and subsequently stored as a value for a Redis key (regardless of key type). |
static <T extends Serializable> |
decode(List<byte[]> byteList)
This helper method will assume the List
JRedis method such as JRedis#smembers(String) , and that this
list contains the encode(Serializable) ed bytes of the parametric type T . |
static byte[] |
encode(String value) |
static <T extends Serializable> |
encode(T obj)
This helper method will serialize the given serializable object of type T
to a byte[], suitable for use as a value for a redis key, regardless of the key
type.
|
static Map<String,byte[]> |
toDataDictionary(Map<byte[],byte[]> binaryMap) |
static double |
toDouble(byte[] bs) |
static List<Double> |
toDouble(List<byte[]> bytearray) |
static Long |
toLong(byte[] bytes)
NOTE: Isn't this already in
Convert.toLong(byte[]) ?
TODO: get rid of this method
This helper method will convert the byte[] to a Long . |
static List<Long> |
toLong(List<byte[]> bytearray) |
static String |
toStr(byte[] bytes) |
static List<String> |
toStr(List<byte[]> bytearray)
This helper method is mainly intended for use with a list of
keys returned from Redis, given that it will use the UTF-8
Charset in decoding the byte array. |
public static final String SUPPORTED_CHARSET_NAME
public static final Charset SUPPORTED_CHARSET
public static final List<String> toStr(List<byte[]> bytearray)
Charset
in decoding the byte array. Typical use would
be to convert from the ListJRedis.keys()
bytearray
- public static final Map<String,byte[]> toDataDictionary(Map<byte[],byte[]> binaryMap)
public static final String toStr(byte[] bytes)
bytes
- String.String(byte[])
or null if bytes is null.public static final byte[] encode(String value)
public static final Long toLong(byte[] bytes)
Convert.toLong(byte[])
?
TODO: get rid of this method
This helper method will convert the byte[] to a Long
.bytes
- public static double toDouble(byte[] bs)
bs
- bytes of the ascii string representation of a double number. E.g. "2.002".getBytes()public static final <T extends Serializable> List<T> decode(List<byte[]> byteList)
JRedis
method such as JRedis#smembers(String)
, and that this
list contains the encode(Serializable)
ed bytes of the parametric type T
.
Specifically, this method will instantiate an ArrayList
for type T, of equal
size to the size of bytelist List
. Then it will iterate over the byte list
and for each byte[] list item call decode(byte[])
.
Usage example:
List memberBytes = redis.smembers("my-object-set");
List members = decode (memberBytes);
T
- byteList
- public static final <T extends Serializable> T decode(byte[] bytes)
ObjectOutputStream
and subsequently stored as a value for a Redis key (regardless of key type).
Specifically, this method will simply do:
ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(bytes));
t = (T) oin.readObject();
and returning the reference t, and throwing any exceptions encountered along
the way.
This method is the decoding peer of encode(Serializable)
, and it is
assumed (and certainly recommended) that you use these two methods in tandem.
Naturally, all caveats, rules, and considerations that generally apply to Serializable
and the Object Serialization specification apply.
T
- bytes
- T
public static final <T extends Serializable> byte[] encode(T obj)
T
- obj
- Copyright © 2009–2018. All rights reserved.