|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.helidb.lang.serializer.FixedSizeBigIntegerSerializer
public class FixedSizeBigIntegerSerializer
This is a Serializer
for BigInteger
values to byte
arrays of a fixed size.
A value is serialized to a big-endian byte arrays using BigInteger
's
constructor and toByteArray
methods. Before the array containing the
BigInteger
data, the serialized value contains a size value of the
BigInteger
data (which may be less than the fixed size of this
object). For fixed sizes of less than 256 bytes, one unsigned byte is used to
represent the size. For sizes of 256 bytes or larger, a signed integer (four
bytes) is used for the size.
The configured size of this object determines how big the serialized BigInteger
:s can be. For an object size of of n
bytes, where n
is less than or equal to 256 bytes, the maximum BigInteger
value
is 2^((n - 1)*8 - 1) - 1
and the minimum value is -2^((n -
1)*8 - 1)
. For n
values larger than 256, the maximum value is
2^((n - 4)*8 - 1) - 1
and the minimum value is -2^((n - 4)*8 -
1)
.
This serializer does not handle null
values.
BigInteger
,
FixedSizeBigIntegerNullSerializer
,
ConfigurableLengthLongSerializer
Constructor Summary | |
---|---|
FixedSizeBigIntegerSerializer(int dataSize)
Create a new Serializer . |
Method Summary | |
---|---|
protected int |
getMaxBigIntSize()
Get the maximum size of BigInteger data. |
int |
getSerializedSize()
If the serialized data produced by this serializer always is of the same size, return that size (in number of bytes). |
BigInteger |
interpret(byte[] barr)
Interpret the data in the byte array to an object of the type
handled by the Serializer implementation. |
BigInteger |
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? |
BigInteger |
read(InputStream is,
int dataSize)
Read a value from the InputStream . |
BigInteger |
read(RandomAccess ra,
int dataSize)
Read a value from the RandomAccess ' current position. |
BigInteger |
readBigInteger(InputStream is)
Read a BigInteger value from the current position of the InputStream . |
BigInteger |
readBigInteger(RandomAccess ra)
Read a BigInteger value from the current position of the RandomAccess . |
byte[] |
serialize(BigInteger val)
Serialize the supplied object into a new byte array. |
int |
serialize(BigInteger 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 |
---|
public FixedSizeBigIntegerSerializer(int dataSize) throws IllegalArgumentException
Serializer
.
dataSize
- The size of serialized values in bytes. If the data size
is 256 bytes or less, one unsigned byte is used to represent the size of
the BigInteger
byte array. If the data size is greater than 256
bytes, a total of five bytes is used to represent the size of the BigInteger
byte array. The byte or bytes used for representing the data
size are included in this parameter.
IllegalArgumentException
- If the size is less than two bytes.Method Detail |
---|
protected int getMaxBigIntSize()
BigInteger
data.
public final int getSerializedSize()
Serializer
-1
is
returned.
getSerializedSize
in interface Serializer<BigInteger>
-1
if the size of the serialized data is variable.public boolean isNullValuesPermitted()
Serializer
null
values?
isNullValuesPermitted
in interface Serializer<BigInteger>
false
, always.public BigInteger interpret(byte[] barr, int offset, int length)
Serializer
byte
array to an object of the type
handled by the Serializer
implementation.
interpret
in interface Serializer<BigInteger>
barr
- The byte
array containing the data.offset
- The start position of the data.length
- The length of the data.
Serializer.interpret(byte[])
public BigInteger interpret(byte[] barr)
Serializer
byte
array to an object of the type
handled by the Serializer
implementation.
interpret
in interface Serializer<BigInteger>
barr
- The byte
array containing the data.
Serializer.interpret(byte[], int, int)
public int serialize(BigInteger val, byte[] barr, int offset)
Serializer
byte
array.
serialize
in interface Serializer<BigInteger>
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.
public byte[] serialize(BigInteger val)
Serializer
byte
array.
serialize
in interface Serializer<BigInteger>
val
- The object to serialize.
byte
array.public BigInteger readBigInteger(RandomAccess ra) throws NotEnoughDataException, WrappedIOException
BigInteger
value from the current position of the RandomAccess
.
ra
- The RandomAccess
to read from. The current position of
this is incremented by the number of bytes that are used to represent the
BigInteger
value.
BigInteger
value.
NotEnoughDataException
- If enough data cannot be read.
WrappedIOException
- On I/O errors.public BigInteger readBigInteger(InputStream is) throws NotEnoughDataException, WrappedIOException
BigInteger
value from the current position of the InputStream
.
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 BigInteger
value.
BigInteger
value.
NotEnoughDataException
- If enough data cannot be read.
WrappedIOException
- If an IOException
is encountered while
reading data.public BigInteger read(RandomAccess ra, int dataSize)
Serializer
RandomAccess
' current position. The
position in the RandomAccess
is incremented by size
bytes.
read
in interface Serializer<BigInteger>
ra
- The RandomAccess
to read from.dataSize
- The size of the value.
public BigInteger read(InputStream is, int dataSize)
Serializer
InputStream
.
read
in interface Serializer<BigInteger>
is
- The InputStream
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 |