Class ByteArray

java.lang.Object
org.opendaylight.raft.spi.ByteArray
All Implemented Interfaces:
SizedStreamSource, StreamSource

@NonNullByDefault public abstract sealed class ByteArray extends Object implements SizedStreamSource
The moral equivalent of a byte[], but perhaps allocated in chunks so as to be GC-friendly.
  • Method Details

    • openStream

      public abstract InputStream openStream()
      Description copied from interface: StreamSource
      Open an InputStream.
      Specified by:
      openStream in interface StreamSource
      Returns:
      an InputStream
    • size

      public final long size()
      Description copied from interface: SizedStreamSource
      Returns the size of this data source, which is to say the number of bytes available for reading from the stream returned by StreamSource.openStream().
      Specified by:
      size in interface SizedStreamSource
      Returns:
      the size of this data source
    • legacySize

      public abstract int legacySize()
      Returns the size of this array.
      Returns:
      the size of this array
    • copyTo

      public abstract void copyTo(DataOutput output) throws IOException
      Copy this array into specified DataOutput.
      Parameters:
      output - the data output
      Throws:
      IOException - if an I/O error occurs
    • copyTo

      public abstract void copyTo(OutputStream output) throws IOException
      Copy this array into specified DataOutput.
      Parameters:
      output - the data output
      Throws:
      IOException - if an I/O error occurs
    • chunks

      public abstract List<byte[]> chunks()
      Returns the list of chunks.
      Returns:
      the list of chunks
    • empty

      public static final ByteArray empty()
      Returns an empty ByteArray.
      Returns:
      an empty ByteArray
    • wrap

      public static final ByteArray wrap(byte[] bytes)
      Wrap a byte[] in a ByteArray.
      Parameters:
      bytes - bytes to wrap
      Returns:
      a ByteArray
    • readFrom

      public static ByteArray readFrom(DataInput in, int size, int chunkSize) throws IOException
      Read a ByteArray from a DataInput.
      Parameters:
      in - the input
      size - size of input
      chunkSize - target chunk size
      Returns:
      a ByteArray
      Throws:
      IOException - if an I/O error occurs
    • toString

      public final String toString()
      Overrides:
      toString in class Object