org.helidb.lang.serializer
Class StringNullSerializer

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

public class StringNullSerializer
extends StringSerializer

This is a String serializer 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.

The singleton instance INSTANCE uses "[null]" to represent null values. It may be used instead of instantiating this class.

For more documentation on String serialization, see StringSerializer.

Since:
1.0
Author:
Karl Gustafsson
See Also:
StringSerializer, ConstantSizeStringNullSerializer, String
In_jar:
helidb-core

Field Summary
static String DEFAULT_NULL_VALUE
          The default special null value.
static StringNullSerializer INSTANCE
          This instance uses the default special null value.
 
Constructor Summary
StringNullSerializer(String nullValue)
          Instantiate the serializer.
 
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.StringSerializer
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

INSTANCE

public static final StringNullSerializer INSTANCE
This instance uses the default special null value. It should be useful in most circumstances.

Constructor Detail

StringNullSerializer

public StringNullSerializer(String nullValue)
Instantiate the serializer.

Parameters:
nullValue - The special String used to represent null values.
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 StringSerializer
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 StringSerializer
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 StringSerializer
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 StringSerializer
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 StringSerializer
Parameters:
barr - The byte array containing the data.
Returns:
The interpreted object.
See Also:
Serializer.interpret(byte[], int, int)