Module hla.rti1516e

Class ByteWrapper

java.lang.Object
hla.rti1516e.encoding.ByteWrapper

public class ByteWrapper extends Object
Utility class for managing data in byte arrays.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Construct a ByteWrapper backed by a zero-length byte array.
    ByteWrapper(byte[] buffer)
    Constructs a ByteWrapper backed by the specified byte array.
    ByteWrapper(byte[] buffer, int offset)
    Constructs a ByteWrapper backed by the specified byte array.
    ByteWrapper(byte[] buffer, int offset, int length)
    Constructs a ByteWrapper backed by the specified byte array.
    ByteWrapper(int length)
    Construct a ByteWrapper backed by a byte array with the specified length.
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    advance(int n)
    Advances the current position by n.
    void
    align(int alignment)
    Advances the current position until the specified alignment is achieved.
    final byte[]
    Returns the backing array.
    final int
    get()
    Reads the next byte of the ByteWrapper.
    final void
    get(byte[] dest)
    Reads dest.length bytes from the ByteWrapper into dest.
    final int
    Reads the next four byte of the ByteWrapper as a hi-endian 32-bit integer.
    final int
    Returns the current position.
    void
    put(byte[] src)
    Writes a byte array to the ByteWrapper and advances the current posisiton by the size of the byte array.
    void
    put(byte[] src, int offset, int count)
    Writes a subset of a byte array to the ByteWrapper and advances the current posisiton by the size of the subset.
    void
    put(int b)
    Writes byte to the ByteWrapper and advances the current position by 1.
    void
    putInt(int value)
    Writes value to the ByteWrapper as a hi-endian 32-bit integer.
    void
    reassign(byte[] buffer, int offset, int length)
    Changes the backing store used by this ByteWrapper.
    int
    Returns the number of remaining bytes in the byte array.
    void
    Resets current position to the start of the ByteWrapper.
    Creates a ByteWrapper backed by the same byte array using the current position as its offset.
    slice(int length)
    Creates a ByteWrapper backed by the same byte array using the current position as its offset, and the specified length to mark the limit.
    Returns a string representation of the ByteWrapper.
    void
    verify(int length)
    Verify that length bytes can be read.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ByteWrapper

      public ByteWrapper()
      Construct a ByteWrapper backed by a zero-length byte array.
    • ByteWrapper

      public ByteWrapper(int length)
      Construct a ByteWrapper backed by a byte array with the specified length.
      Parameters:
      length - length of the backing byte array
    • ByteWrapper

      public ByteWrapper(byte[] buffer)
      Constructs a ByteWrapper backed by the specified byte array. (Changes to the ByteWrapper will write through to the specified byte array.)
      Parameters:
      buffer - backing byte array
    • ByteWrapper

      public ByteWrapper(byte[] buffer, int offset)
      Constructs a ByteWrapper backed by the specified byte array. (Changes to the ByteWrapper will write through to the specified byte array.) The offset will be at the start position. Limit will be at buffer.length.
      Parameters:
      buffer - backing byte array
      offset - start position offset
    • ByteWrapper

      public ByteWrapper(byte[] buffer, int offset, int length)
      Constructs a ByteWrapper backed by the specified byte array. (Changes to the ByteWrapper will write through to the specified byte array.)
      Parameters:
      buffer - backing byte array
      offset - start position offset
      length - length of the segment to use
  • Method Details

    • reassign

      public void reassign(byte[] buffer, int offset, int length)
      Changes the backing store used by this ByteWrapper. Changes to the ByteWrapper will write through to the specified byte array.
      Parameters:
      buffer - backing byte array
      offset - start position offset
      length - length of the segment to use
    • reset

      public void reset()
      Resets current position to the start of the ByteWrapper.
    • verify

      public void verify(int length)
      Verify that length bytes can be read.
      Parameters:
      length - number of byte to verify
      Throws:
      ArrayIndexOutOfBoundsException - if length bytes can not be read
    • getInt

      public final int getInt()
      Reads the next four byte of the ByteWrapper as a hi-endian 32-bit integer. The current position is increased by 4.
      Returns:
      decoded value
      Throws:
      ArrayIndexOutOfBoundsException - if the bytes can not be read
    • get

      public final int get()
      Reads the next byte of the ByteWrapper. The current position is increased by 1.
      Returns:
      decoded value
      Throws:
      ArrayIndexOutOfBoundsException - if the bytes can not be read
    • get

      public final void get(byte[] dest)
      Reads dest.length bytes from the ByteWrapper into dest. The current position is increased by dest.length.
      Parameters:
      dest - destination for the read bytes
      Throws:
      ArrayIndexOutOfBoundsException - if the bytes can not be read
    • putInt

      public void putInt(int value)
      Writes value to the ByteWrapper as a hi-endian 32-bit integer. The current position is increased by 4.
      Parameters:
      value - value to write
      Throws:
      ArrayIndexOutOfBoundsException - if the bytes can not be written
    • put

      public void put(int b)
      Writes byte to the ByteWrapper and advances the current position by 1.
      Parameters:
      b - byte to write
      Throws:
      ArrayIndexOutOfBoundsException - if the bytes can not be written
    • put

      public void put(byte[] src)
      Writes a byte array to the ByteWrapper and advances the current posisiton by the size of the byte array.
      Parameters:
      src - byte array to write
      Throws:
      ArrayIndexOutOfBoundsException - if the bytes can not be written
    • put

      public void put(byte[] src, int offset, int count)
      Writes a subset of a byte array to the ByteWrapper and advances the current posisiton by the size of the subset.
      Parameters:
      src - byte array to write
      offset - offset of subset to write
      count - size of offset to write
      Throws:
      ArrayIndexOutOfBoundsException - if the bytes can not be written
    • array

      public final byte[] array()
      Returns the backing array.
      Returns:
      the backing byte array
    • getPos

      public final int getPos()
      Returns the current position.
      Returns:
      the current potition within the byte array
      See Also:
    • remaining

      public int remaining()
      Returns the number of remaining bytes in the byte array.
      Returns:
      the number of remaining bytes in the byte array
    • advance

      public final void advance(int n)
      Advances the current position by n.
      Parameters:
      n - number of positions to advance
      Throws:
      ArrayIndexOutOfBoundsException - if the position can not be advanced
    • align

      public void align(int alignment)
      Advances the current position until the specified alignment is achieved.
      Parameters:
      alignment - alignment that the current position must support
    • slice

      public ByteWrapper slice()
      Creates a ByteWrapper backed by the same byte array using the current position as its offset.
      Returns:
      a new ByteWrapper backed by the same byte array starting at the current position
    • slice

      public ByteWrapper slice(int length)
      Creates a ByteWrapper backed by the same byte array using the current position as its offset, and the specified length to mark the limit.
      Parameters:
      length - length of the new ByteWrapper
      Returns:
      a new ByteWrapper backed by the same byte array starting at the current position with the defined length
      Throws:
      ArrayIndexOutOfBoundsException - if the length is to long
    • toString

      public String toString()
      Returns a string representation of the ByteWrapper.
      Overrides:
      toString in class Object
      Returns:
      a string representation of the ByteWrapper