Class SerializationUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
packInt
(int value, DataOutput out) Packs the specifiedint
value and writes it to the providedoutput
.static void
packLong
(long value, DataOutput out) Packs the specifiedlong
value and writes it to the providedoutput
.static int
Reads and unpacks anint
value.static long
unpackLong
(DataInput in) Reads and unpacks anlong
value.
-
Method Details
-
packInt
Packs the specifiedint
value and writes it to the providedoutput
.The more leading zeroes in the two's complement binary representation the value has the less bytes its packed representation requires. Thus this method may be inefficient if there are lots of positive numbers greater than or equal to 228 or lots of any negative numbers whose packed representation requires 5 bytes. In this case use
DataOutput.writeInt(int)
method.In case there are lots of both positive and negative numbers with low absolute values consider applying ZigZag encoding before packing.
This method has been borrowed from MapDB but originally comes from Kryo Framework, author Nathan Sweet. It was modified to fit MapDB needs.
- Parameters:
value
- The value to pack and write.out
- The output to write the packed value to.- Throws:
IOException
- in case an I/O error occurs.
-
unpackInt
Reads and unpacks anint
value.This method has been borrowed from MapDB but originally comes from Kryo Framework, author Nathan Sweet. It was modified to fit MapDB needs.
- Parameters:
in
- The input to read the packed value from.- Returns:
- the read and unpacked value.
- Throws:
IOException
- in case an I/O error occurs.
-
packLong
Packs the specifiedlong
value and writes it to the providedoutput
.The more leading zeroes in the two's complement binary representation the value has the less bytes its packed representation requires. Thus this method may be inefficient if there are lots of positive numbers greater than or equal to 256 whose packed representation requires at least 9 bytes or lots of any negative numbers whose packed representation requires 10 bytes. In this case use
DataOutput.writeLong(long)
method.In case there are lots of both positive and negative numbers with low absolute values consider applying ZigZag encoding before packing.
This method has been borrowed from MapDB but originally comes from Kryo Framework, author Nathan Sweet. It was modified to fit MapDB needs.
- Parameters:
value
- The value to pack and write.out
- The output to write the packed value to.- Throws:
IOException
- in case an I/O error occurs.
-
unpackLong
Reads and unpacks anlong
value.This method has been borrowed from MapDB but originally comes from Kryo Framework, author Nathan Sweet. It was modified to fit MapDB needs.
- Parameters:
in
- The input to read the packed value from.- Returns:
- the read and unpacked value.
- Throws:
IOException
- in case an I/O error occurs.
-