Class SerializationUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidpackInt(int value, DataOutput out) Packs the specifiedintvalue and writes it to the providedoutput.static voidpackLong(long value, DataOutput out) Packs the specifiedlongvalue and writes it to the providedoutput.static intReads and unpacks anintvalue.static longunpackLong(DataInput in) Reads and unpacks anlongvalue.
-
Method Details
-
packInt
Packs the specifiedintvalue 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 anintvalue.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 specifiedlongvalue 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 anlongvalue.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.
-