org.helidb.lang.serializer
Class UnsignedByteSerializer

java.lang.Object
  extended by org.helidb.lang.serializer.UnsignedByteSerializer
All Implemented Interfaces:
Serializer<Short>

public class UnsignedByteSerializer
extends Object
implements Serializer<Short>

A Serializer for unsigned byte values (between 0 and 255). Every unsigned byte value serialized by this object is represented as a byte array of length one. Deserialized values are represented by Short objects.

This serializer does not handle null values.

The singleton instance INSTANCE may be used instead of creating a new object of this class.

Since:
1.0
Author:
Karl Gustafsson
See Also:
Byte, ByteSerializer
In_jar:
helidb-core

Field Summary
static int DATA_SIZE
          One byte.
static UnsignedByteSerializer INSTANCE
          The singleton instance.
 
Constructor Summary
UnsignedByteSerializer()
           
 
Method Summary
 int getSerializedSize()
          If the serialized data produced by this serializer always is of the same size, return that size (in number of bytes).
 Short interpret(byte[] barr)
          Interpret the data in the byte array to an object of the type handled by the Serializer implementation.
 Short 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?
 Short read(InputStream is, int dataSize)
          Read a value from the InputStream.
 Short read(RandomAccess ra, int dataSize)
          Read a value from the RandomAccess' current position.
 Short readUnsignedByte(InputStream is)
          Read an unsigned byte value from the current position of the InputStream.
 Short readUnsignedByte(RandomAccess ra)
          Read an unsigned byte value from the current position of the RandomAccess.
 byte[] serialize(Short value)
          Serialize the supplied object into a new byte array.
 int serialize(Short value, byte[] arr, 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
 

Field Detail

INSTANCE

public static final UnsignedByteSerializer INSTANCE
The singleton instance. May be used instead of instantiating this class.


DATA_SIZE

public static final int DATA_SIZE
One byte.

See Also:
Constant Field Values
Constructor Detail

UnsignedByteSerializer

public UnsignedByteSerializer()
Method Detail

interpret

public Short 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<Short>
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 Short 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<Short>
Parameters:
barr - The byte array containing the data.
Returns:
The interpreted object.
See Also:
Serializer.interpret(byte[], int, int)

serialize

public int serialize(Short value,
                     byte[] arr,
                     int offset)
Description copied from interface: Serializer
Serialize the supplied object into the byte array.

Specified by:
serialize in interface Serializer<Short>
Parameters:
value - The object to serialize.
arr - 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(Short value)
Description copied from interface: Serializer
Serialize the supplied object into a new byte array.

Specified by:
serialize in interface Serializer<Short>
Parameters:
value - The object to serialize.
Returns:
The object serialized into a byte array.

getSerializedSize

public int getSerializedSize()
Description copied from interface: Serializer
If the serialized data produced by this serializer always is of the same size, return that size (in number of bytes). Otherwise -1 is returned.

Specified by:
getSerializedSize in interface Serializer<Short>
Returns:
1, always.

isNullValuesPermitted

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

Specified by:
isNullValuesPermitted in interface Serializer<Short>
Returns:
false, always.

readUnsignedByte

public Short readUnsignedByte(RandomAccess ra)
                       throws NotEnoughDataException,
                              WrappedIOException
Read an unsigned byte value from the current position of the RandomAccess.

Parameters:
ra - The RandomAccess to read from. The current position of this is incremented by 1 bytes.
Returns:
The unsigned byte value, represented as a Short value between 0 and 255.
Throws:
DatabaseException - If 1 bytes cannot be read.
WrappedIOException - On I/O errors.
NotEnoughDataException

readUnsignedByte

public Short readUnsignedByte(InputStream is)
                       throws NotEnoughDataException,
                              WrappedIOException
Read an unsigned byte value from the current position of the InputStream.

Parameters:
is - The InputStream to read from. The current position of the stream is incremented by 1 bytes.
Returns:
The unsigned byte value, represented as a Short value between 0 and 255.
Throws:
NotEnoughDataException - If 1 bytes cannot be read.
WrappedIOException - If an IOException is encountered while reading data.

read

public Short read(RandomAccess ra,
                  int dataSize)
Description copied from interface: Serializer
Read a value from the RandomAccess' current position. The position in the RandomAccess is incremented by size bytes.

Specified by:
read in interface Serializer<Short>
Parameters:
ra - The RandomAccess to read from.
dataSize - The size of the value.
Returns:
The value.

read

public Short read(InputStream is,
                  int dataSize)
Description copied from interface: Serializer
Read a value from the InputStream.

Specified by:
read in interface Serializer<Short>
Parameters:
is - The InputStream to read from.
dataSize - The size of the value.
Returns:
The value.