java.lang.Object
com.ibm.jvm.trace.format.api.ByteStream
-
Constructor Summary
ConstructorsConstructorDescriptionByteStream
(byte[] data) ByteStream
(byte[] data, int offset) ByteStream
(byte[] data, int offset, int length) -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(byte[] data) void
add
(byte[] data, int offset) void
add
(byte[] data, int offset, int length) byte
get()
void
get
(byte[] dst) void
get
(byte[] dst, int offset, int length) byte
get
(int index) getASCIIString
(int length) getBigInteger
(int bytes) reads the specified number of bytes and turns them in to a positive BigIntegerdouble
double
getDouble
(int index) float
getFloat()
float
getFloat
(int index) int
int
getInt()
int
getInt
(int index) long
getLong()
long
getLong
(int index) short
getShort()
short
getShort
(int index) long
long
getUnsignedInt
(int index) char
char
getUTF8Char
(int index) Constructs a string.order()
void
Default order is big endian and that's what you'll get if you pass null in.byte
peek()
int
peek
(byte[] dest) void
put
(byte[] data, int index) This method, in addition to putByte, is negatively indexed, i.e. it indexes from the end of the data.byte
put
(byte b, int index) This takes a negative index and puts byte b in the index specified working back from the end of the rawData as if it were one large array allowing negative addressing.int
void
reverseBytes
(byte[] data) void
setGuardBytes
(int bytes) void
skip
(int bytes) int
truncate
(byte[] bytes) This allows you to strip off the last n bytes from the stream so long as they've not been reached.void
truncate
(int bytes) This allows you to strip off the last n bytes from the stream so long as they've not been reached.
-
Constructor Details
-
ByteStream
public ByteStream(byte[] data) -
ByteStream
public ByteStream(byte[] data, int offset) -
ByteStream
public ByteStream(byte[] data, int offset, int length) -
ByteStream
public ByteStream()
-
-
Method Details
-
reverseBytes
public void reverseBytes(byte[] data) -
add
public void add(byte[] data) -
add
public void add(byte[] data, int offset) -
add
public void add(byte[] data, int offset, int length) -
get
public byte get() -
get
public byte get(int index) -
getUTF8Char
public char getUTF8Char() -
getUTF8Char
public char getUTF8Char(int index) -
getDouble
public double getDouble() -
getDouble
public double getDouble(int index) -
getFloat
public float getFloat() -
getFloat
public float getFloat(int index) -
getInt
public int getInt() -
getInt
public int getInt(int index) -
getUnsignedInt
public long getUnsignedInt() -
getUnsignedInt
public long getUnsignedInt(int index) -
getLong
public long getLong() -
getLong
public long getLong(int index) -
getShort
public short getShort() -
getShort
public short getShort(int index) -
getASCIIString
-
getASCIIString
-
getUTF8String
Constructs a string. This has a prerequisite that the string is prefixed with a short specifying it's length.- Returns:
- Throws:
UnsupportedEncodingException
-
getBigInteger
reads the specified number of bytes and turns them in to a positive BigInteger- Parameters:
bytes
-- Returns:
-
get
public void get(byte[] dst) -
get
public void get(byte[] dst, int offset, int length) -
order
-
order
Default order is big endian and that's what you'll get if you pass null in.- Parameters:
order
-
-
setGuardBytes
public void setGuardBytes(int bytes) -
getGuardBytes
public int getGuardBytes() -
truncate
public void truncate(int bytes) This allows you to strip off the last n bytes from the stream so long as they've not been reached. This will remove data until it hits the beginning of the stream, then will throw an exception. If an exception is thrown the stream will be completely empty, all data discarded.- Parameters:
bytes
- - the number of bytes to remove- Throws:
BufferUnderflowException
-
truncate
public int truncate(byte[] bytes) This allows you to strip off the last n bytes from the stream so long as they've not been reached. This will remove data until it hits the beginning of the stream, then will return. The data that's truncated will be placed into the provided array, filling from the end (i.e. if there's insufficient data in the stream to fill the array then the initial bytes in the array will be zero.- Parameters:
bytes
- - the number of bytes to remove- Returns:
- - the number of bytes truncated
-
remaining
public int remaining() -
peek
- Throws:
BufferUnderflowException
-
peek
public int peek(byte[] dest) -
skip
public void skip(int bytes) -
put
public void put(byte[] data, int index) This method, in addition to putByte, is negatively indexed, i.e. it indexes from the end of the data. This is primarily because it's hard to be sure where the start of the data is in relation to the bytes we know we can modify, i.e. those bytes that are guarded. put(data, -1) will insert the bytes in data in the last but one position of the stream, moving the last byte in the stream out by data.length and increase the count of guarded bytes by data.length- Parameters:
data
- - the data to insertindex
- - the negative index at which to insert, must be within the guard bytes
-
put
public byte put(byte b, int index) This takes a negative index and puts byte b in the index specified working back from the end of the rawData as if it were one large array allowing negative addressing. Positive indexes throw index out of bounds. It is worth noting that an index of -1 means the last byte present, i.e. we are not zero indexed.- Parameters:
b
- - the original byte we're replacingindex
-
-