corda / net.corda.core.utilities / ByteSequence

ByteSequence

sealed class ByteSequence : Comparable<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.

Properties

bytes

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

abstract val bytes: ByteArray

offset

The start position of the sequence within the byte array.

val offset: Int

size

The number of bytes this sequence represents.

val size: Int

Functions

compareTo

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.

open fun compareTo(other: ByteSequence): Int

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.

fun copy(): ByteSequence

copyBytes

Same as copy but returns just the new byte array.

fun copyBytes(): ByteArray

equals

open fun equals(other: Any?): Boolean

hashCode

open fun hashCode(): Int

open

Returns a ByteArrayInputStream of the bytes.

fun open(): ByteArrayInputStream

putTo

Write this sequence to a ByteBuffer.

fun putTo(buffer: ByteBuffer): ByteBuffer

slice

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.

fun slice(start: Int = 0, end: Int = size): ByteBuffer

subSequence

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 OpaqueBytes does.

fun subSequence(offset: Int, size: Int): ByteSequence

take

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

fun take(n: Int): ByteSequence

toString

open fun toString(): String

writeTo

Write this sequence to an OutputStream.

fun writeTo(output: OutputStream): Unit

Companion Object Functions

of

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

fun of(bytes: ByteArray, offset: Int = 0, size: Int = bytes.size): ByteSequence

Extension Functions

deserialize

Convenience extension method for deserializing a ByteSequence, utilising the defaults.

fun <T : Any> ByteSequence.deserialize(serializationFactory: SerializationFactory = SerializationFactory.defaultFactory, context: SerializationContext = serializationFactory.defaultContext): T

deserializeWithCompatibleContext

Additionally returns SerializationContext which was used for encoding. It might be helpful to know SerializationContext to use the same encoding in the reply.

fun <T : Any> ByteSequence.deserializeWithCompatibleContext(serializationFactory: SerializationFactory = SerializationFactory.defaultFactory, context: SerializationContext = serializationFactory.defaultContext): ObjectWithCompatibleContext<T>

Inheritors

OpaqueBytes

A simple class that wraps a byte array and makes the equals/hashCode/toString methods work as you actually expect. In an ideal JVM this would be a value type and be completely overhead free. Project Valhalla is adding such functionality to Java, but it won't arrive for a few years yet!

open class OpaqueBytes : ByteSequence

OpaqueBytesSubSequence

Class is public for serialization purposes.

class OpaqueBytesSubSequence : ByteSequence