public class LongPacker extends Object
long values.| Modifier and Type | Class and Description |
|---|---|
static interface |
LongPacker.IByteBuffer
Narrow interface to support packing against different buffer classes.
|
| Constructor and Description |
|---|
LongPacker() |
| Modifier and Type | Method and Description |
|---|---|
static int |
getByteLength(long v)
Return the #of non-zero bytes in the packed long value.
|
static int |
getNibbleLength(long v)
Return the #of non-zero nibbles, counting from the first non-zero nibble
in the long value.
|
static int |
packLong(DataOutput os,
long v)
Packs a non-negative long value into the minimum #of bytes in which the
value can be represented and writes those bytes onto the output stream.
|
static int |
packLong(long v,
byte[] pbuf,
LongPacker.IByteBuffer buf)
Packs a non-negative long value into the minimum #of bytes in which the
value can be represented and writes those bytes onto the buffer.
|
static int |
packLong(OutputStream os,
long v)
Packs a non-negative long value into the minimum #of bytes in which the
value can be represented and writes those bytes onto the output stream.
|
static int |
unpackInt(DataInput is)
Convenience method unpacks long and throws an exception if the value
exceeds
Integer.MAX_VALUE. |
static int |
unpackInt(InputStream is)
Convenience method unpacks long and throws an exception if the value
exceeds
Integer.MAX_VALUE. |
static long |
unpackLong(byte[] buf,
int off)
Unpack a long value from the buffer position.
|
static long |
unpackLong(DataInput is)
Unpack a long value from the input stream.
|
static long |
unpackLong(InputStream is)
Unpack a long value from the input stream.
|
public static int packLong(DataOutput os, long v) throws IOException
[0|1|2|3|4|5|6|7]
1 - - - nbytes = 8, clear high bit and interpret this plus the next 7 bytes as a long.
0 1 1 1 nbytes = 7, clear high nibble and interpret this plus the next 6 bytes as a long.
0 1 1 0 nbytes = 6, clear high nibble and interpret this plus the next 5 bytes as a long.
0 1 0 1 nbytes = 5, clear high nibble and interpret this plus the next 4 bytes as a long.
0 1 0 0 nbytes = 4, clear high nibble and interpret this plus the next 3 bytes as a long.
0 0 1 1 nbytes = 3, clear high nibble and interpret this plus the next 3 bytes as a long.
0 0 1 0 nbytes = 2, clear high nibble and interpret this plus the next byte as a long.
0 0 0 1 nbytes = 1, clear high nibble. value is the low nibble.
IOExceptionpublic static int packLong(OutputStream os, long v) throws IOException
[0|1|2|3|4|5|6|7]
1 - - - nbytes = 8, clear high bit and interpret this plus the next 7 bytes as a long.
0 1 1 1 nbytes = 7, clear high nibble and interpret this plus the next 6 bytes as a long.
0 1 1 0 nbytes = 6, clear high nibble and interpret this plus the next 5 bytes as a long.
0 1 0 1 nbytes = 5, clear high nibble and interpret this plus the next 4 bytes as a long.
0 1 0 0 nbytes = 4, clear high nibble and interpret this plus the next 3 bytes as a long.
0 0 1 1 nbytes = 3, clear high nibble and interpret this plus the next 3 bytes as a long.
0 0 1 0 nbytes = 2, clear high nibble and interpret this plus the next byte as a long.
0 0 0 1 nbytes = 1, clear high nibble. value is the low nibble.
IOExceptionpublic static final int packLong(long v,
byte[] pbuf,
LongPacker.IByteBuffer buf)
[0|1|2|3|4|5|6|7]
1 - - - nbytes = 8, clear high bit and interpret this plus the next 7 bytes as a long.
0 1 1 1 nbytes = 7, clear high nibble and interpret this plus the next 6 bytes as a long.
0 1 1 0 nbytes = 6, clear high nibble and interpret this plus the next 5 bytes as a long.
0 1 0 1 nbytes = 5, clear high nibble and interpret this plus the next 4 bytes as a long.
0 1 0 0 nbytes = 4, clear high nibble and interpret this plus the next 3 bytes as a long.
0 0 1 1 nbytes = 3, clear high nibble and interpret this plus the next 3 bytes as a long.
0 0 1 0 nbytes = 2, clear high nibble and interpret this plus the next byte as a long.
0 0 0 1 nbytes = 1, clear high nibble. value is the low nibble.
v - The unsigned long value.public static int getNibbleLength(long v)
0L is considered to be one
nibble for our purposes.v - The long value.public static int getByteLength(long v)
v - The long value.public static long unpackLong(DataInput is) throws IOException
is - The input stream.IOExceptionpublic static long unpackLong(InputStream is) throws IOException
is - The input stream.IOExceptionpublic static final long unpackLong(byte[] buf,
int off)
buf - The bufferoff - The offset from which the data will be unpacked.public static int unpackInt(DataInput is) throws IOException
Integer.MAX_VALUE.is - The input stream.IOExceptionpublic static int unpackInt(InputStream is) throws IOException
Integer.MAX_VALUE.is - The input stream.IOExceptionCopyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.