Package com.forgerock.opendj.util
Class PackedLong
- java.lang.Object
-
- com.forgerock.opendj.util.PackedLong
-
public final class PackedLong extends Object
Provides static methods to manipulate compact long representation. Compact long allow to stores unsigned long values up to 56 bits using a variable number of bytes from 1 to 8. The binary representations of this compact encoding has the interesting properties of maintaining correct order of values when compared.
-
-
Field Summary
Fields Modifier and Type Field Description static longCOMPACTED_MAX_VALUEMaximum value that can be stored with a compacted representation.static intMAX_COMPACT_SIZEMaximum size in bytes of a compact encoded value.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intgetEncodedSize(long value)Get the number of bytes required to store the given value using the compact long representation.static longreadCompactUnsignedLong(InputStream is)Decode and get the value of the compact long contained in the specifiedInputStream.static intwriteCompactUnsigned(OutputStream os, long value)Append the compact representation of the value into theOutputStream.
-
-
-
Field Detail
-
MAX_COMPACT_SIZE
public static final int MAX_COMPACT_SIZE
Maximum size in bytes of a compact encoded value.- See Also:
- Constant Field Values
-
COMPACTED_MAX_VALUE
public static final long COMPACTED_MAX_VALUE
Maximum value that can be stored with a compacted representation.- See Also:
- Constant Field Values
-
-
Method Detail
-
writeCompactUnsigned
public static int writeCompactUnsigned(OutputStream os, long value) throws IOException
Append the compact representation of the value into theOutputStream.- Parameters:
os-OutputStreamwhere the compact representation will be written.value- Value to be encoded and written in the compact long format.- Returns:
- Number of bytes which has been written in the buffer.
- Throws:
IOException- if problem appear in the underlyingOutputStream
-
getEncodedSize
public static int getEncodedSize(long value)
Get the number of bytes required to store the given value using the compact long representation.- Parameters:
value- Value to get the compact representation's size.- Returns:
- Number of bytes required to store the compact long representation of the value.
-
readCompactUnsignedLong
public static long readCompactUnsignedLong(InputStream is) throws IOException
Decode and get the value of the compact long contained in the specifiedInputStream.- Parameters:
is- Stream where to read the compact unsigned long- Returns:
- The long value.
- Throws:
IOException- If the first byte cannot be read for any reason other than the end of the file, if the input stream has been closed, or if some other I/O error occurs.
-
-