|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.helidb.lang.serializer.ConstantSizeStringSerializer
public class ConstantSizeStringSerializer
This Serializer serializes strings into constant size byte arrays.
When instantiating this class, the client chooses the Charset to be
used to serialize text.
It is important to know how the selected Charset encodes characters,
how many bytes a character occupies and if the Charset adds a header
to the encoded information. For instance
Since creating CharsetEncoder and CharsetDecoder objects are
fairly expensive operations, this object keeps one CharsetEncoder and
one CharsetDecoder instance for the target charset. It protects both
instances with the object's intrinsic lock (synchronized). If several threads
are to use a serializer for a certain charset, consider giving them one
serializer instance each to avoid contention.
This serializer does not handle null values.
StringSerializer,
ConstantSizeStringNullSerializer| Constructor Summary | |
|---|---|
ConstantSizeStringSerializer(Charset cs,
int length,
boolean truncateInput)
Create a new serializer. |
|
| Method Summary | |
|---|---|
int |
getSerializedSize()
Get the size of serialized data. |
String |
interpret(byte[] barr)
Interpret the data in the byte array to an object of the type
handled by the Serializer implementation. |
String |
interpret(byte[] barr,
int offset,
int length)
Interpret the data in the byte array to an object of the type
handled by the Serializer implementation. |
boolean |
isNullValuesPermitted()
Does this serializer permit null values? |
String |
read(InputStream is,
int dataSize)
Read a value from the InputStream. |
String |
read(RandomAccess ra,
int dataSize)
Read a value from the RandomAccess' current position. |
byte[] |
serialize(String s)
Serialize the supplied object into a new byte array. |
int |
serialize(String s,
byte[] barr,
int offset)
Serialize the supplied object into the byte array. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ConstantSizeStringSerializer(Charset cs,
int length,
boolean truncateInput)
throws IllegalArgumentException
cs - The Charset to use for encoding text.length - The maximum length in bytes of serialized text. To
calculate a good maximum length, it is important to know how the selected
Charset encodes text. See the class code above.truncateInput - If the input exceeds the maximum length, should it
be truncated? If not, the serialize(String) methods throws an
exception instead.
IllegalArgumentException - If the Charset cannot encode
text (its canEncode method returns false), or if the
maximum length is too short to fit one character in the selected Charset.| Method Detail |
|---|
public boolean isNullValuesPermitted()
Serializernull values?
isNullValuesPermitted in interface Serializer<String>false.public int getSerializedSize()
getSerializedSize in interface Serializer<String>
public int serialize(String s,
byte[] barr,
int offset)
Serializerbyte array.
serialize in interface Serializer<String>s - The object to serialize.barr - The byte array to serialize it to.offset - The start position to write data at in the byte array.
public byte[] serialize(String s)
Serializerbyte array.
serialize in interface Serializer<String>s - The object to serialize.
byte array.
public String interpret(byte[] barr,
int offset,
int length)
Serializerbyte array to an object of the type
handled by the Serializer implementation.
interpret in interface Serializer<String>barr - The byte array containing the data.offset - The start position of the data.length - The length of the data.
Serializer.interpret(byte[])public String interpret(byte[] barr)
Serializerbyte array to an object of the type
handled by the Serializer implementation.
interpret in interface Serializer<String>barr - The byte array containing the data.
Serializer.interpret(byte[], int, int)
public String read(InputStream is,
int dataSize)
SerializerInputStream.
read in interface Serializer<String>is - The InputStream to read from.dataSize - The size of the value.
public String read(RandomAccess ra,
int dataSize)
SerializerRandomAccess' current position. The
position in the RandomAccess is incremented by size
bytes.
read in interface Serializer<String>ra - The RandomAccess to read from.dataSize - The size of the value.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||