public final class ByteSequenceReader extends Object
ByteSequence .
ByteSequenceReader must be created using the associated
ByteSequence's asReader() method.| Modifier and Type | Method and Description |
|---|---|
byte |
get()
Relative get method.
|
void |
get(byte[] b)
Relative bulk get method.
|
void |
get(byte[] b,
int offset,
int length)
Relative bulk get method.
|
int |
getBERLength()
Relative get method for reading a multi-byte BER length.
|
ByteSequence |
getByteSequence(int length)
Relative bulk get method.
|
ByteString |
getByteString(int length)
Relative bulk get method.
|
long |
getCompactUnsigned()
Relative get method for reading a compacted long value.
|
int |
getInt()
Relative get method for reading an integer value.
|
long |
getLong()
Relative get method for reading a long value.
|
short |
getShort()
Relative get method for reading an short value.
|
String |
getString(int length)
Relative get method for reading a UTF-8 encoded string.
|
byte |
peek()
Returns the byte situated at the current position.
|
byte |
peek(int offset)
Returns the byte situated at the given offset from current position.
|
int |
position()
Returns this reader's position.
|
void |
position(int pos)
Sets this reader's position.
|
int |
remaining()
Returns the number of bytes between the current position and the end of
the underlying byte sequence.
|
void |
rewind()
Rewinds this reader's position to zero.
|
void |
skip(int length)
Skips the given number of bytes.
|
String |
toString() |
public byte get()
IndexOutOfBoundsException - If there are fewer bytes remaining in this reader than are
required to satisfy the request, that is, if
remaining()
< 1.public void get(byte[] b)
src.get(b);Behaves in exactly the same way as the invocation:
src.get(b, 0, b.length);
b - The byte array into which bytes are to be written.IndexOutOfBoundsException - If there are fewer bytes remaining in this reader than are
required to satisfy the request, that is, if
remaining()
< b.length.public void get(byte[] b, int offset, int length)
length bytes from this reader
into the given array, starting at the current position of this reader and
at the given offset in the array. The position of this reader is
then incremented by length. In other words, an invocation of this
method of the form:
src.get(b, offset, length);Has exactly the same effect as the loop:
for (int i = offset; i < offset + length; i++)
b[i] = src.get();
Except that it first checks that there are sufficient bytes in this
buffer and it is potentially much more efficient.b - The byte array into which bytes are to be written.offset - The offset within the array of the first byte to be written;
must be non-negative and no larger than b.length.length - The number of bytes to be written to the given array; must be
non-negative and no larger than b.length .IndexOutOfBoundsException - If there are fewer bytes remaining in this reader than are
required to satisfy the request, that is, if
remaining()
< length.public int getBERLength()
IndexOutOfBoundsException - If there are fewer bytes remaining in this reader than are
required to satisfy the request.public ByteSequence getByteSequence(int length)
ByteSequence whose content is
the next length bytes from this reader, starting at the current
position of this reader. The position of this reader is then incremented
by length.
NOTE: The value returned from this method should NEVER be cached as it prevents the contents of the underlying byte stream from being garbage collected.
length - The length of the byte sequence to be returned.length bytes
from this reader.IndexOutOfBoundsException - If there are fewer bytes remaining in this reader than are
required to satisfy the request, that is, if
remaining()
< length.public ByteString getByteString(int length)
ByteString whose content is
the next length bytes from this reader, starting at the current
position of this reader. The position of this reader is then incremented
by length.
An invocation of this method of the form:
src.getByteString(length);Has exactly the same effect as:
src.getByteSequence(length).toByteString();NOTE: The value returned from this method should NEVER be cached as it prevents the contents of the underlying byte stream from being garbage collected.
length - The length of the byte string to be returned.length bytes
from this reader.IndexOutOfBoundsException - If there are fewer bytes remaining in this reader than are
required to satisfy the request, that is, if
remaining()
< length.public int getInt()
IndexOutOfBoundsException - If there are fewer bytes remaining in this reader than are
required to satisfy the request, that is, if
remaining()
< 4.public long getLong()
IndexOutOfBoundsException - If there are fewer bytes remaining in this reader than are
required to satisfy the request, that is, if
remaining()
< 8.public long getCompactUnsigned()
IndexOutOfBoundsException - If there are fewer bytes remaining in this reader than are
required to satisfy the request.public short getShort()
IndexOutOfBoundsException - If there are fewer bytes remaining in this reader than are
required to satisfy the request, that is, if
remaining()
< 2.public String getString(int length)
length - The number of bytes to read and decode.IndexOutOfBoundsException - If there are fewer bytes remaining in this reader than are
required to satisfy the request, that is, if
remaining()
< length.public int position()
public void position(int pos)
pos - The new position value; must be non-negative and no larger
than the length of the underlying byte sequence.IndexOutOfBoundsException - If the position is negative or larger than the length of the
underlying byte sequence.public int remaining()
public void rewind()
An invocation of this method of the form:
src.rewind();Has exactly the same effect as:
src.position(0);
public byte peek()
IndexOutOfBoundsException - If the position is negative or larger than the length of the
underlying byte sequence.public byte peek(int offset)
offset - The offset where to look at from current position.IndexOutOfBoundsException - If the position is negative or larger than the length of the
underlying byte sequence.public void skip(int length)
An invocation of this method of the form:
src.skip(length);Has exactly the same effect as:
src.position(position() + length);
length - The number of bytes to skip.IndexOutOfBoundsException - If the new position is less than 0 or greater than the length
of the underlying byte sequence.Copyright © 2011-2015 ForgeRock AS. All Rights Reserved.