net.i2p.data

## Class ByteArray

- java.lang.Object
- - net.i2p.data.ByteArray

- All Implemented Interfaces:
    Serializable, Comparable<ByteArray>
  Direct Known Subclasses:
    MsgID, Token

      public class ByteArray
      extends Object
      implements Serializable, Comparable<ByteArray>

  Wrap up an array of bytes so that they can be compared and placed in hashes, maps, and the like.
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ByteArray()` Creates an empty ByteArray.
    `ByteArray(byte[] data)` Sets valid = data.length, unless data is null Sets offset = 0
    `ByteArray(byte[] data, int offset, int length)` Sets offset = offset Sets valid = length

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `compareTo(ByteArray ba)`
    `boolean` | `equals(Object o)`
    `byte[]` | `getData()` Returns the underlying byte array.
    `int` | `getOffset()` Returns the offset into the byte array.
    `int` | `getValid()` Count how many of the bytes in the array are 'valid'.
    `int` | `hashCode()`
    `void` | `setData(byte[] data)` Sets the underlying byte array.
    `void` | `setOffset(int offset)` Sets the offset into the byte array.
    `void` | `setValid(int valid)` Sets the number of valid bytes.
    `String` | `toBase64()` Returns this ByteArray as a Base64 encoded string.
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### ByteArray

          public ByteArray()

      Creates an empty ByteArray.

    - #### ByteArray

          public ByteArray(byte[] data)

      Sets valid = data.length, unless data is null Sets offset = 0
      Parameters:
        `data` - the byte array, may be null

    - #### ByteArray

          public ByteArray(byte[] data,
                           int offset,
                           int length)

      Sets offset = offset Sets valid = length
      Parameters:
        `data` - the byte array, may be null but why would you do that
        `offset` - the starting offset
        `length` - the valid length

  - ### Method Detail

    - #### compareTo

          public final int compareTo(ByteArray ba)

      Specified by:
        `compareTo` in interface `Comparable<ByteArray>`

    - #### equals

          public final boolean equals(Object o)

      Overrides:
        `equals` in class `Object`

    - #### getData

          public byte[] getData()

      Returns the underlying byte array.
      Returns:
        the byte data, may be null

    - #### getOffset

          public int getOffset()

      Returns the offset into the byte array.
      Returns:
        the offset

    - #### getValid

          public int getValid()

      Count how many of the bytes in the array are 'valid'. this property does not necessarily have meaning for all byte arrays.
      Returns:
        the number of valid bytes

    - #### hashCode

          public final int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### setData

          public void setData(byte[] data)

      Sets the underlying byte array. Warning, does not set valid
      Parameters:
        `data` - the new byte array

    - #### setOffset

          public void setOffset(int offset)

      Sets the offset into the byte array.
      Parameters:
        `offset` - the new offset

    - #### setValid

          public void setValid(int valid)

      Sets the number of valid bytes.
      Parameters:
        `valid` - the new valid count

    - #### toBase64

          public final String toBase64()

      Returns this ByteArray as a Base64 encoded string.
      Returns:
        the Base64 encoded string

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`