Class ByteStream

java.lang.Object
com.ibm.jvm.trace.format.api.ByteStream

public class ByteStream extends Object
  • 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

      public String getASCIIString(int length)
    • getASCIIString

      public String getASCIIString()
    • getUTF8String

      public String getUTF8String() throws UnsupportedEncodingException
      Constructs a string. This has a prerequisite that the string is prefixed with a short specifying it's length.
      Returns:
      Throws:
      UnsupportedEncodingException
    • getBigInteger

      public BigInteger getBigInteger(int bytes)
      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

      public ByteOrder order()
    • order

      public void order(ByteOrder 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

      public byte peek() throws BufferUnderflowException
      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 insert
      index - - 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:
      index -
      b - - the original byte we're replacing