tuweni / org.apache.tuweni.bytes / Bytes

Bytes

interface Bytes : Comparable<Bytes!> (source)

A value made of bytes.

This interface makes no thread-safety guarantee, and a Bytes value is generally not thread safe. However, specific implementations may be thread-safe. For instance, the value returned by #copy is guaranteed to be thread-safe as it is immutable.

Properties

EMPTY

The empty value (with 0 bytes).

static val EMPTY: Bytes!

Functions

and

Return a bit-wise AND of these bytes and the supplied bytes. If this value and the supplied value are different lengths, then the shorter will be zero-padded to the left.

open fun and(other: Bytes!): Bytes!

Calculate a bit-wise AND of these bytes and the supplied bytes.

open fun <T : MutableBytes!> and(other: Bytes!, result: T): T

appendHexTo

Append this value as a sequence of hexadecimal characters.

open fun <T : Appendable!> appendHexTo(appendable: T): T

appendTo

Append the bytes of this value to the ByteBuffer.

open fun appendTo(byteBuffer: ByteBuffer!): Unit

Append the bytes of this value to the provided Vert.x Buffer.

open fun appendTo(buffer: Buffer!): Unit

bitLength

Provides the number of bits following and including the highest-order ("leftmost") one-bit, or zero if all bits are zero.

open fun bitLength(): Int

commonPrefix

Return a slice over the common prefix between this set of bytes and another.

open fun commonPrefix(other: Bytes!): Bytes!

commonPrefixLength

Return the number of bytes in common between this set of bytes and another.

open fun commonPrefixLength(other: Bytes!): Int

compareTo

open fun compareTo(other: Bytes!): Int

concatenate

Create a value containing the concatenation of the values provided.

open static fun concatenate(values: MutableList<Bytes!>!): Bytes!
open static fun concatenate(vararg values: Bytes!): Bytes!

copy

Return a value equivalent to this one but guaranteed to 1) be deeply immutable (i.e. the underlying value will be immutable) and 2) to not retain more bytes than exposed by the value.

abstract fun copy(): Bytes!

copyTo

Copy the bytes of this value to the provided mutable one, which must have the same size.

open fun copyTo(destination: MutableBytes!): Unit

Copy the bytes of this value to the provided mutable one from a particular offset.

open fun copyTo(destination: MutableBytes!, destinationOffset: Int): Unit

fromBase64String

Parse a base 64 string into a Bytes value.

open static fun fromBase64String(str: CharSequence!): Bytes!

fromHexString

Parse a hexadecimal string into a Bytes value.

open static fun fromHexString(str: CharSequence!): Bytes!
open static fun fromHexString(str: CharSequence!, destinationSize: Int): Bytes!

fromHexStringLenient

Parse a hexadecimal string into a Bytes value.

open static fun fromHexStringLenient(str: CharSequence!): Bytes!

Parse a hexadecimal string into a Bytes value of the provided size.

open static fun fromHexStringLenient(str: CharSequence!, destinationSize: Int): Bytes!

get

Retrieve a byte in this value.

abstract fun get(i: Int): Byte

getInt

Retrieve the 4 bytes starting at the provided index in this value as an integer.

open fun getInt(i: Int): Int
open fun getInt(i: Int, order: ByteOrder!): Int

getLong

Retrieves the 8 bytes starting at the provided index in this value as a long.

open fun getLong(i: Int): Long
open fun getLong(i: Int, order: ByteOrder!): Long

hasLeadingZero

Whether the bytes start with a zero bit value.

open fun hasLeadingZero(): Boolean

hasLeadingZeroByte

Whether the bytes start with a zero byte value.

open fun hasLeadingZeroByte(): Boolean

isEmpty

Whether this value contains no bytes.

open fun isEmpty(): Boolean

isZero

Whether this value has only zero bytes.

open fun isZero(): Boolean

minimalBytes

Return the smallest bytes value whose bytes correspond to the provided long. That is, the returned value may be of size less than 8 if the provided long has leading zero bytes.

open static fun minimalBytes(value: Long): Bytes!

mutableCopy

Return a new mutable value initialized with the content of this value.

abstract fun mutableCopy(): MutableBytes!

not

Return a bit-wise NOT of these bytes.

open fun not(): Bytes!

Calculate a bit-wise NOT of these bytes.

open fun <T : MutableBytes!> not(result: T): T

numberOfLeadingZeroBytes

Provides the number of leading zero bytes of the value

open fun numberOfLeadingZeroBytes(): Int

numberOfLeadingZeros

Provides the number of zero bits preceding the highest-order ("leftmost") one-bit, or size() * 8 if all bits * are zero.

open fun numberOfLeadingZeros(): Int

numberOfTrailingZeroBytes

Provides the number of trailing zero bytes of the value.

open fun numberOfTrailingZeroBytes(): Int

of

Create a value that contains the specified bytes in their specified order.

open static fun of(vararg bytes: Byte): Bytes!
open static fun of(vararg bytes: Int): Bytes!

ofUnsignedInt

Return a 4-byte value corresponding to the provided value interpreted as an unsigned int.

open static fun ofUnsignedInt(value: Long): Bytes!
open static fun ofUnsignedInt(value: Long, order: ByteOrder!): Bytes!

ofUnsignedLong

Return an 8-byte value corresponding to the provided value interpreted as an unsigned long.

open static fun ofUnsignedLong(value: Long): Bytes!
open static fun ofUnsignedLong(value: Long, order: ByteOrder!): Bytes!

ofUnsignedShort

Return a 2-byte value corresponding to the provided value interpreted as an unsigned short.

open static fun ofUnsignedShort(value: Int): Bytes!
open static fun ofUnsignedShort(value: Int, order: ByteOrder!): Bytes!

or

Return a bit-wise OR of these bytes and the supplied bytes.

open fun or(other: Bytes!): Bytes!

Calculate a bit-wise OR of these bytes and the supplied bytes.

open fun <T : MutableBytes!> or(other: Bytes!, result: T): T

random

Generate random bytes.

open static fun random(size: Int): Bytes!
open static fun random(size: Int, generator: Random!): Bytes!

reverse

Computes the reverse array of bytes of the current bytes.

open fun reverse(): Bytes!

secure

Wrap the provided byte array as a Bytes value, encrypted in memory.

open static fun secure(value: ByteArray!): Bytes!

Wrap a slice of a byte array as a Bytes value, encrypted in memory.

open static fun secure(value: ByteArray!, offset: Int, length: Int): Bytes!

shiftLeft

Shift all bits in this value to the left.

open fun shiftLeft(distance: Int): Bytes!

Shift all bits in this value to the left.

open fun <T : MutableBytes!> shiftLeft(distance: Int, result: T): T

shiftRight

Shift all bits in this value to the right.

open fun shiftRight(distance: Int): Bytes!

Shift all bits in this value to the right.

open fun <T : MutableBytes!> shiftRight(distance: Int, result: T): T

size

Provides the number of bytes this value represents.

abstract fun size(): Int

slice

Create a new value representing (a view of) a slice of the bytes of this value.

open fun slice(i: Int): Bytes!
abstract fun slice(i: Int, length: Int): Bytes!

toArray

Extract the bytes of this value into a byte array.

open fun toArray(): ByteArray!
open fun toArray(byteOrder: ByteOrder!): ByteArray!

toArrayUnsafe

Get the bytes represented by this value as byte array.

open fun toArrayUnsafe(): ByteArray!

toBase64String

Provides this value represented as base 64

open fun toBase64String(): String!

toBigInteger

The BigInteger corresponding to interpreting these bytes as a two's-complement signed integer.

open fun toBigInteger(): BigInteger!
open fun toBigInteger(order: ByteOrder!): BigInteger!

toEllipsisHexString

open fun toEllipsisHexString(): String!

toHexString

Provides this value represented as hexadecimal, starting with "0x".

open fun toHexString(): String!

toInt

The value corresponding to interpreting these bytes as an integer.

open fun toInt(): Int
open fun toInt(order: ByteOrder!): Int

toLong

The value corresponding to interpreting these bytes as a long.

open fun toLong(): Long
open fun toLong(order: ByteOrder!): Long

toQuantityHexString

Provides this value represented as a minimal hexadecimal string (without any leading zero, except if it's valued zero or empty, in which case it returns 0x0).

open fun toQuantityHexString(): String!

toShortHexString

Provides this value represented as a minimal hexadecimal string (without any leading zero)

open fun toShortHexString(): String!

toUnprefixedHexString

Provides this value represented as hexadecimal, with no prefix

open fun toUnprefixedHexString(): String!

toUnsignedBigInteger

The BigInteger corresponding to interpreting these bytes as an unsigned integer.

open fun toUnsignedBigInteger(): BigInteger!
open fun toUnsignedBigInteger(order: ByteOrder!): BigInteger!

trimLeadingZeros

Return a slice of representing the same value but without any leading zero bytes.

open fun trimLeadingZeros(): Bytes!

update

Update the provided message digest with the bytes of this value.

open fun update(digest: MessageDigest!): Unit

wrap

Wrap the provided byte array as a Bytes value.

open static fun wrap(value: ByteArray!): Bytes!

Wrap a slice of a byte array as a Bytes value.

open static fun wrap(value: ByteArray!, offset: Int, length: Int): Bytes!

Wrap a list of other values into a concatenated view.

open static fun wrap(vararg values: Bytes!): Bytes!

wrapBuffer

Wrap a full Vert.x Buffer as a Bytes value.

open static fun wrapBuffer(buffer: Buffer!): Bytes!

Wrap a slice of a Vert.x Buffer as a Bytes value.

open static fun wrapBuffer(buffer: Buffer!, offset: Int, size: Int): Bytes!

wrapByteBuf

Wrap a full Netty ByteBuf as a Bytes value.

open static fun wrapByteBuf(byteBuf: ByteBuf!): Bytes!

Wrap a slice of a Netty ByteBuf as a Bytes value.

open static fun wrapByteBuf(byteBuf: ByteBuf!, offset: Int, size: Int): Bytes!

wrapByteBuffer

Wrap a full Java NIO ByteBuffer as a Bytes value.

open static fun wrapByteBuffer(byteBuffer: ByteBuffer!): Bytes!

Wrap a slice of a Java NIO ByteBuf as a Bytes value.

open static fun wrapByteBuffer(byteBuffer: ByteBuffer!, offset: Int, size: Int): Bytes!

xor

Return a bit-wise XOR of these bytes and the supplied bytes.

open fun xor(other: Bytes!): Bytes!

Calculate a bit-wise XOR of these bytes and the supplied bytes.

open fun <T : MutableBytes!> xor(other: Bytes!, result: T): T

Inheritors

AbstractBytes

An abstract Bytes value that provides implementations of #equals(Object), #hashCode() and #toString().

abstract class AbstractBytes : Bytes

Bytes32

A Bytes value that is guaranteed to contain exactly 32 bytes.

interface Bytes32 : Bytes

Bytes48

A Bytes value that is guaranteed to contain exactly 48 bytes.

interface Bytes48 : Bytes

DelegatingBytes

A class that holds and delegates all operations to its inner bytes field.

open class DelegatingBytes : AbstractBytes, Bytes

MutableBytes

A mutable Bytes value.

interface MutableBytes : Bytes