org.helidb.lang.serializer
Class ConfigurableLengthLongSerializer

java.lang.Object
  extended by org.helidb.lang.serializer.ConfigurableLengthLongSerializer
All Implemented Interfaces:
Serializer<Long>
Direct Known Subclasses:
ConfigurableLengthLongNullSerializer

public class ConfigurableLengthLongSerializer
extends Object
implements Serializer<Long>

This Serializer serializes Long values to a big-endian byte array of configurable size. The length of the byte array determines how big the serialized Long:s can be. For a byte array length of n bytes, the maximum Integer value is 2^(n*8), except if n has its maximum value of 8, then the maximum value is Long.MAX_VALUE. Negative values are only supported if n == 8.

Since:
1.0
Author:
Karl Gustafsson
See Also:
LongSerializer, ConfigurableLengthLongNullSerializer, ConfigurableLengthIntegerSerializer, FixedSizeBigIntegerSerializer, Long
In_jar:
helidb-core

Constructor Summary
ConfigurableLengthLongSerializer(int dataSize)
          Create a new Serializer.
 
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).
 Long interpret(byte[] barr)
          Interpret the data in the byte array to an object of the type handled by the Serializer implementation.
 Long 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?
 Long read(InputStream is, int dataSize)
          Read a value from the InputStream.
 Long read(RandomAccess ra, int dataSize)
          Read a value from the RandomAccess' current position.
 Long readLong(InputStream is)
          Read a Long value from the current position of the InputStream.
 Long readLong(RandomAccess ra)
          Read a Long value from the current position of the RandomAccess.
 byte[] serialize(Long val)
          Serialize the supplied object into a new byte array.
 int serialize(Long val, 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

ConfigurableLengthLongSerializer

public ConfigurableLengthLongSerializer(int dataSize)
                                 throws IllegalArgumentException
Create a new Serializer.

Parameters:
dataSize - The number of bytes used to represent the Long:s.
Throws:
IllegalArgumentException - If the data size is not in the range 1 <= dataSize <= 8.
Method Detail

getSerializedSize

public final 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<Long>
Returns:
The size of the serialized data in number of byte if it is always the same, or -1 if the size of the serialized data is variable.

isNullValuesPermitted

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

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

interpret

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

serialize

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

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

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

readLong

public Long readLong(RandomAccess ra)
              throws NotEnoughDataException,
                     WrappedIOException
Read a Long value from the current position of the RandomAccess.

Parameters:
ra - The RandomAccess to read from. The current position of this is incremented by the number of bytes that are used to represent the Long value.
Returns:
The Long value.
Throws:
NotEnoughDataException - If enough data cannot be read.
WrappedIOException - On I/O errors

readLong

public Long readLong(InputStream is)
              throws NotEnoughDataException,
                     WrappedIOException
Read a Long value from the current position of the InputStream.

Parameters:
is - The InputStream to read from. The current position of the stream is incremented by the number of bytes that are used to represent the Long value
Returns:
The Long value.
Throws:
NotEnoughDataException - If enough data cannot be read.
WrappedIOException - If an IOException is encountered while reading data.

read

public Long 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<Long>
Parameters:
ra - The RandomAccess to read from.
dataSize - The size of the value.
Returns:
The value.

read

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

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