|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.lucene.util.Vint8
public class Vint8
Variable-length encoding of 32-bit integers, into 8-bit bytes. A number is encoded as follows:
Compatibility:
This class has been used in products that have shipped to customers, and is needed to
decode legacy data. Do not modify this class in ways that will break compatibility.
Nested Class Summary | |
---|---|
static class |
Vint8.Position
Because Java lacks call-by-reference, this class boxes the decoding position, which is initially set by the caller, and returned after decoding, incremented by the number of bytes processed. |
Field Summary | |
---|---|
static int |
MAXIMUM_BYTES_NEEDED
The maximum number of bytes needed to encode a number using Vint8 . |
Method Summary | |
---|---|
static int |
bytesNeeded(int number)
Returns the number of bytes needed to encode number . |
static int |
decode(byte[] bytes,
Vint8.Position pos)
Decodes a 32-bit integer from bytes , beginning at offset pos.pos . |
static int |
decode(InputStream in)
Decodes a 32-bit integer from bytes read from in . |
static int |
encode(int number,
byte[] dest,
int start)
Encodes number into dest , starting at offset start from
the beginning of the array. |
static void |
encode(int number,
OutputStream out)
Encodes number to out . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int MAXIMUM_BYTES_NEEDED
Vint8
.
Method Detail |
---|
public static int bytesNeeded(int number)
number
.
number
- The number whose encoded length is needed.
number
.public static void encode(int number, OutputStream out) throws IOException
number
to out
.
number
- The value to be written in encoded form, to out
.out
- The output stream receiving the encoded bytes.
IOException
- If there is a problem writing to out
.public static int encode(int number, byte[] dest, int start)
number
into dest
, starting at offset start
from
the beginning of the array. This method assumes dest
is large enough to
hold the required number of bytes.
number
- The number to be encoded.dest
- The destination array.start
- The starting offset in the array.
public static int decode(byte[] bytes, Vint8.Position pos)
bytes
, beginning at offset pos.pos
.
The decoded value is returned, and pos.pos
is incremented by the number of
bytes processed.
bytes
- The byte array containing an encoded value.pos
- On entry, the starting position in the array; on return, one greater
than the position of the last byte decoded in the call.
public static int decode(InputStream in) throws IOException
in
. Bytes are read,
one at a time, from in
, and it is assumed they represent a 32-bit
integer encoded using this class's encoding scheme. The decoded value is
returned.
in
- The input stream containing the encoded bytes.
EOFException
- If the stream ends before a value has been decoded.
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |