ByteSequence
Keywords: net.corda.core.utilities.ByteSequence class
Date: 2023-09-18

net.corda.core.utilities

## Class ByteSequence

- net.corda.core.utilities.ByteSequence

- Direct Known Subclasses:
    OpaqueBytes, OpaqueBytesSubSequence

      public class ByteSequence

  An abstraction of a byte array, with offset and size that does no copying of bytes unless asked to.

  The data of interest typically starts at position offset within the `bytes` and is size bytes long.

  See Also:
    `bytes`

- - ### Field Detail

    - #### Companion

          public static net.corda.core.utilities.ByteSequence.Companion Companion

  - ### Method Detail

    - #### getBytes

          @NotNull
          public kotlin.Array[] getBytes()

      The underlying bytes. Some implementations may choose to make a copy of the underlying ByteArray for security reasons. For example, `class OpaqueBytes`.

      See Also:
        ByteArray, `class OpaqueBytes`

    - #### open

          @NotNull
          public java.io.ByteArrayInputStream open()

      Returns a ByteArrayInputStream of the bytes.

      See Also:
        ByteArrayInputStream

    - #### subSequence

          @NotNull
          public ByteSequence subSequence(int offset,
                                                   int size)

      Create a sub-sequence of this sequence. A copy of the underlying array may be made, if a subclass overrides `bytes` to do so, as `class OpaqueBytes` does.

      Parameters:
        `offset` - The offset within this sequence to start the new sequence. Note: not the offset within the backing array.
        `size` - The size of the intended sub sequence.
      See Also:
        `bytes`, `class OpaqueBytes`

    - #### take

          @NotNull
          public ByteSequence take(int n)

      Take the first n bytes of this sequence as a sub-sequence. See `subSequence` for further semantics.

      See Also:
        `subSequence`

    - #### slice

          @NotNull
          public java.nio.ByteBuffer slice(int start,
                                                    int end)

      A new read-only ByteBuffer view of this sequence or part of it. If `start` or `end` are negative then IllegalArgumentException is thrown, otherwise they are clamped if necessary. This method cannot be used to get bytes before offset or after offset+size, and never makes a new array.

      See Also:
        ByteBuffer, `start`, `end`, IllegalArgumentException

    - #### writeTo

          public void writeTo(@NotNull
                              java.io.OutputStream output)

      Write this sequence to an OutputStream.

      See Also:
        OutputStream

    - #### putTo

          @NotNull
          public java.nio.ByteBuffer putTo(@NotNull
                                                    java.nio.ByteBuffer buffer)

      Write this sequence to a ByteBuffer.

      See Also:
        ByteBuffer

    - #### copy

          @NotNull
          public ByteSequence copy()

      Copy this sequence, complete with new backing array. This can be helpful to break references to potentially large backing arrays from small sub-sequences.

    - #### copyBytes

          @NotNull
          public kotlin.Array[] copyBytes()

      Same as `copy` but returns just the new byte array.

      See Also:
        `copy`

    - #### compareTo

          public int compareTo(@NotNull
                               ByteSequence other)

      Compare byte arrays byte by byte. Arrays that are shorter are deemed less than longer arrays if all the bytes of the shorter array equal those in the same position of the longer array.

    - #### equals

          public boolean equals(@Nullable
                                java.lang.Object other)

    - #### hashCode

          public int hashCode()

    - #### toString

          @NotNull
          public java.lang.String toString()

    - #### getOffset

          public int getOffset()

      The start position of the sequence within the byte array.

    - #### getSize

          public int getSize()

      The number of bytes this sequence represents.

    - #### of

          @JvmStatic
           @JvmOverloads
           @NotNull
          public static ByteSequence of(@NotNull
                                                                            kotlin.Array[] bytes,
                                                                            int offset,
                                                                            int size)

      Construct a `class ByteSequence` given a ByteArray and optional offset and size, that represents that potentially sub-sequence of bytes.

      See Also:
        `class ByteSequence`, ByteArray

    - #### of

          @JvmStatic
           @JvmOverloads
           @NotNull
          public static ByteSequence of(@NotNull
                                                                            kotlin.Array[] bytes,
                                                                            int offset)

      Construct a `class ByteSequence` given a ByteArray and optional offset and size, that represents that potentially sub-sequence of bytes.

      See Also:
        `class ByteSequence`, ByteArray

    - #### of

          @JvmStatic
           @JvmOverloads
           @NotNull
          public static ByteSequence of(@NotNull
                                                                            kotlin.Array[] bytes)

      Construct a `class ByteSequence` given a ByteArray and optional offset and size, that represents that potentially sub-sequence of bytes.

      See Also:
        `class ByteSequence`, ByteArray