Class ByteVector

java.lang.Object
org.eclipse.sisu.space.asm.ByteVector

public class ByteVector extends Object
A dynamically extensible vector of bytes. This class is roughly equivalent to a DataOutputStream on top of a ByteArrayOutputStream, but is more efficient.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) byte[]
    The content of this vector.
    (package private) int
    The actual number of bytes in this vector.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new ByteVector with a default initial capacity.
    ByteVector(byte[] data)
    Constructs a new ByteVector from the given initial data.
    ByteVector(int initialCapacity)
    Constructs a new ByteVector with the given initial capacity.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) final ByteVector
    encodeUtf8(String stringValue, int offset, int maxByteLength)
    Puts an UTF8 string into this byte vector.
    private void
    enlarge(int size)
    Enlarges this byte vector so that it can receive 'size' more bytes.
    (package private) final ByteVector
    put11(int byteValue1, int byteValue2)
    Puts two bytes into this byte vector.
    (package private) final ByteVector
    put112(int byteValue1, int byteValue2, int shortValue)
    Puts two bytes and a short into this byte vector.
    (package private) final ByteVector
    put12(int byteValue, int shortValue)
    Puts a byte and a short into this byte vector.
    (package private) final ByteVector
    put122(int byteValue, int shortValue1, int shortValue2)
    Puts one byte and two shorts into this byte vector.
    putByte(int byteValue)
    Puts a byte into this byte vector.
    putByteArray(byte[] byteArrayValue, int byteOffset, int byteLength)
    Puts an array of bytes into this byte vector.
    putInt(int intValue)
    Puts an int into this byte vector.
    putLong(long longValue)
    Puts a long into this byte vector.
    putShort(int shortValue)
    Puts a short into this byte vector.
    putUTF8(String stringValue)
    Puts an UTF8 string into this byte vector.
    int
    Returns the actual number of bytes in this vector.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • data

      byte[] data
      The content of this vector. Only the first length bytes contain real data.
    • length

      int length
      The actual number of bytes in this vector.
  • Constructor Details

    • ByteVector

      public ByteVector()
      Constructs a new ByteVector with a default initial capacity.
    • ByteVector

      public ByteVector(int initialCapacity)
      Constructs a new ByteVector with the given initial capacity.
      Parameters:
      initialCapacity - the initial capacity of the byte vector to be constructed.
    • ByteVector

      ByteVector(byte[] data)
      Constructs a new ByteVector from the given initial data.
      Parameters:
      data - the initial data of the new byte vector.
  • Method Details

    • size

      public int size()
      Returns the actual number of bytes in this vector.
      Returns:
      the actual number of bytes in this vector.
    • putByte

      public ByteVector putByte(int byteValue)
      Puts a byte into this byte vector. The byte vector is automatically enlarged if necessary.
      Parameters:
      byteValue - a byte.
      Returns:
      this byte vector.
    • put11

      final ByteVector put11(int byteValue1, int byteValue2)
      Puts two bytes into this byte vector. The byte vector is automatically enlarged if necessary.
      Parameters:
      byteValue1 - a byte.
      byteValue2 - another byte.
      Returns:
      this byte vector.
    • putShort

      public ByteVector putShort(int shortValue)
      Puts a short into this byte vector. The byte vector is automatically enlarged if necessary.
      Parameters:
      shortValue - a short.
      Returns:
      this byte vector.
    • put12

      final ByteVector put12(int byteValue, int shortValue)
      Puts a byte and a short into this byte vector. The byte vector is automatically enlarged if necessary.
      Parameters:
      byteValue - a byte.
      shortValue - a short.
      Returns:
      this byte vector.
    • put112

      final ByteVector put112(int byteValue1, int byteValue2, int shortValue)
      Puts two bytes and a short into this byte vector. The byte vector is automatically enlarged if necessary.
      Parameters:
      byteValue1 - a byte.
      byteValue2 - another byte.
      shortValue - a short.
      Returns:
      this byte vector.
    • putInt

      public ByteVector putInt(int intValue)
      Puts an int into this byte vector. The byte vector is automatically enlarged if necessary.
      Parameters:
      intValue - an int.
      Returns:
      this byte vector.
    • put122

      final ByteVector put122(int byteValue, int shortValue1, int shortValue2)
      Puts one byte and two shorts into this byte vector. The byte vector is automatically enlarged if necessary.
      Parameters:
      byteValue - a byte.
      shortValue1 - a short.
      shortValue2 - another short.
      Returns:
      this byte vector.
    • putLong

      public ByteVector putLong(long longValue)
      Puts a long into this byte vector. The byte vector is automatically enlarged if necessary.
      Parameters:
      longValue - a long.
      Returns:
      this byte vector.
    • putUTF8

      public ByteVector putUTF8(String stringValue)
      Puts an UTF8 string into this byte vector. The byte vector is automatically enlarged if necessary.
      Parameters:
      stringValue - a String whose UTF8 encoded length must be less than 65536.
      Returns:
      this byte vector.
    • encodeUtf8

      final ByteVector encodeUtf8(String stringValue, int offset, int maxByteLength)
      Puts an UTF8 string into this byte vector. The byte vector is automatically enlarged if necessary. The string length is encoded in two bytes before the encoded characters, if there is space for that (i.e. if this.length - offset - 2 >= 0).
      Parameters:
      stringValue - the String to encode.
      offset - the index of the first character to encode. The previous characters are supposed to have already been encoded, using only one byte per character.
      maxByteLength - the maximum byte length of the encoded string, including the already encoded characters.
      Returns:
      this byte vector.
    • putByteArray

      public ByteVector putByteArray(byte[] byteArrayValue, int byteOffset, int byteLength)
      Puts an array of bytes into this byte vector. The byte vector is automatically enlarged if necessary.
      Parameters:
      byteArrayValue - an array of bytes. May be null to put byteLength null bytes into this byte vector.
      byteOffset - index of the first byte of byteArrayValue that must be copied.
      byteLength - number of bytes of byteArrayValue that must be copied.
      Returns:
      this byte vector.
    • enlarge

      private void enlarge(int size)
      Enlarges this byte vector so that it can receive 'size' more bytes.
      Parameters:
      size - number of additional bytes that this byte vector should be able to receive.