org.helidb.lang.serializer
Class ConstantSizeStringNullSerializer

java.lang.Object
  extended by org.helidb.lang.serializer.ConstantSizeStringSerializer
      extended by org.helidb.lang.serializer.ConstantSizeStringNullSerializer
All Implemented Interfaces:
Serializer<String>

public class ConstantSizeStringNullSerializer
extends ConstantSizeStringSerializer

This is a variant of the ConstantSizeStringSerializer that can handle null values. null values are encoded to a special string. Other String:s that happen to start with the special String are escaped. This should be transparent to the client.

For more documentation on String serialization, see ConstantSizeStringSerializer.

Since:
1.0
Author:
Karl Gustafsson
See Also:
StringNullSerializer
In_jar:
helidb-core

Field Summary
static String DEFAULT_NULL_VALUE
          The default special null value.
 
Constructor Summary
ConstantSizeStringNullSerializer(Charset cs, int length, boolean truncateText)
          Create a serializer that will use the default null value "[null]" .
ConstantSizeStringNullSerializer(Charset cs, int length, boolean truncateText, String nullValue)
          Create a serializer that will use the supplied text for encoding null values.
 
Method Summary
 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?
 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 org.helidb.lang.serializer.ConstantSizeStringSerializer
getSerializedSize, read, read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_NULL_VALUE

public static final String DEFAULT_NULL_VALUE
The default special null value.

See Also:
Constant Field Values
Constructor Detail

ConstantSizeStringNullSerializer

public ConstantSizeStringNullSerializer(Charset cs,
                                        int length,
                                        boolean truncateText)
                                 throws IllegalArgumentException
Create a serializer that will use the default null value "[null]" .

Parameters:
cs - The Charset to use for serializing text.
length - The length in bytes of the serialized data.
truncateText - Should text that is too long be truncated when serializing? Otherwise serialize(String) will throw an exception.
Throws:
IllegalArgumentException - On invalid input parameters. See ConstantSizeStringSerializer.ConstantSizeStringSerializer(Charset, int, boolean) .
See Also:
ConstantSizeStringSerializer.ConstantSizeStringSerializer(Charset, int, boolean)

ConstantSizeStringNullSerializer

public ConstantSizeStringNullSerializer(Charset cs,
                                        int length,
                                        boolean truncateText,
                                        String nullValue)
                                 throws IllegalArgumentException
Create a serializer that will use the supplied text for encoding null values.

Parameters:
cs - The Charset to use for serializing text.
length - The length in bytes of the serialized data.
truncateText - Should text that is too long be truncated when serializing? Otherwise serialize(String) will throw an exception.
nullValue - The text used for encoding null values. It is not verified by this constructor that the null value actually fits in the maximum length.
Throws:
IllegalArgumentException - On invalid input parameters. See ConstantSizeStringSerializer.ConstantSizeStringSerializer(Charset, int, boolean) .
See Also:
ConstantSizeStringSerializer.ConstantSizeStringSerializer(Charset, int, boolean)
Method Detail

isNullValuesPermitted

public boolean isNullValuesPermitted()
Description copied from interface: Serializer
Does this serializer permit null values?

Specified by:
isNullValuesPermitted in interface Serializer<String>
Overrides:
isNullValuesPermitted in class ConstantSizeStringSerializer
Returns:
true, always.

serialize

public int serialize(String s,
                     byte[] barr,
                     int offset)
Description copied from interface: Serializer
Serialize the supplied object into the byte array.

Specified by:
serialize in interface Serializer<String>
Overrides:
serialize in class ConstantSizeStringSerializer
Parameters:
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.
Returns:
The number of bytes written to the array.

serialize

public byte[] serialize(String s)
Description copied from interface: Serializer
Serialize the supplied object into a new byte array.

Specified by:
serialize in interface Serializer<String>
Overrides:
serialize in class ConstantSizeStringSerializer
Parameters:
s - The object to serialize.
Returns:
The object serialized into a byte array.

interpret

public String interpret(byte[] barr,
                        int offset,
                        int length)
Description copied from interface: Serializer
Interpret the data in the byte array to an object of the type handled by the Serializer implementation.

Specified by:
interpret in interface Serializer<String>
Overrides:
interpret in class ConstantSizeStringSerializer
Parameters:
barr - The byte array containing the data.
offset - The start position of the data.
length - The length of the data.
Returns:
The interpreted object.
See Also:
Serializer.interpret(byte[])

interpret

public String interpret(byte[] barr)
Description copied from interface: Serializer
Interpret the data in the byte array to an object of the type handled by the Serializer implementation.

Specified by:
interpret in interface Serializer<String>
Overrides:
interpret in class ConstantSizeStringSerializer
Parameters:
barr - The byte array containing the data.
Returns:
The interpreted object.
See Also:
Serializer.interpret(byte[], int, int)