Interface Bytes
- All Superinterfaces:
Comparable<Bytes>
- All Known Subinterfaces:
Bytes32,Bytes48,MutableBytes,MutableBytes32,MutableBytes48
- All Known Implementing Classes:
AbstractBytes,DelegatingBytes,DelegatingBytes32,DelegatingBytes48,DelegatingMutableBytes,MutableByteBufferWrappingBytes
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiondefault BytesReturn a bit-wise AND of these bytes and the supplied bytes.default <T extends MutableBytes>
TCalculate a bit-wise AND of these bytes and the supplied bytes.default <T extends Appendable>
TappendHexTo(T appendable) Append this value as a sequence of hexadecimal characters.default voidappendTo(io.vertx.core.buffer.Buffer buffer) Append the bytes of this value to the provided Vert.xBuffer.default voidappendTo(ByteBuffer byteBuffer) Append the bytes of this value to theByteBuffer.default intProvides the number of bits following and including the highest-order ("leftmost") one-bit, or zero if all bits are zero.default BytescommonPrefix(Bytes other) Return a slice over the common prefix between this set of bytes and another.default intcommonPrefixLength(Bytes other) Return the number of bytes in common between this set of bytes and another.default intstatic Bytesconcatenate(List<Bytes> values) Create a value containing the concatenation of the values provided.static Bytesconcatenate(Bytes... values) Create a value containing the concatenation of the values provided.copy()Return a value equivalent to this one but guaranteed to 1) be deeply immutable (i.e.default voidcopyTo(MutableBytes destination) Copy the bytes of this value to the provided mutable one, which must have the same size.default voidcopyTo(MutableBytes destination, int destinationOffset) Copy the bytes of this value to the provided mutable one from a particular offset.static BytesParse a base 64 string into aBytesvalue.static BytesParse a hexadecimal string into aBytesvalue.static BytesfromHexString(CharSequence str, int destinationSize) Parse a hexadecimal string into aBytesvalue.static BytesParse a hexadecimal string into aBytesvalue.static BytesfromHexStringLenient(CharSequence str, int destinationSize) Parse a hexadecimal string into aBytesvalue of the provided size.byteget(int i) Retrieve a byte in this value.default intgetInt(int i) Retrieve the 4 bytes starting at the provided index in this value as an integer.default intRetrieve the 4 bytes starting at the provided index in this value as an integer.default longgetLong(int i) Retrieves the 8 bytes starting at the provided index in this value as a long.default longRetrieves the 8 bytes starting at the provided index in this value as a long.default booleanWhether the bytes start with a zero bit value.default booleanWhether the bytes start with a zero byte value.default booleanisEmpty()Whether this value contains no bytes.default booleanisZero()Whether this value has only zero bytes.static BytesminimalBytes(long value) Return the smallest bytes value whose bytes correspond to the provided long.Return a new mutable value initialized with the content of this value.default Bytesnot()Return a bit-wise NOT of these bytes.default <T extends MutableBytes>
Tnot(T result) Calculate a bit-wise NOT of these bytes.default intProvides the number of leading zero bytes of the valuedefault intProvides the number of zero bits preceding the highest-order ("leftmost") one-bit, orsize() * 8if all bits * are zero.default intProvides the number of trailing zero bytes of the value.static Bytesof(byte... bytes) Create a value that contains the specified bytes in their specified order.static Bytesof(int... bytes) Create a value that contains the specified bytes in their specified order.static BytesofUnsignedInt(long value) Return a 4-byte value corresponding to the provided value interpreted as an unsigned int.static BytesofUnsignedInt(long value, ByteOrder order) Return a 4-byte value corresponding to the provided value interpreted as an unsigned int.static BytesofUnsignedLong(long value) Return an 8-byte value corresponding to the provided value interpreted as an unsigned long.static BytesofUnsignedLong(long value, ByteOrder order) Return an 8-byte value corresponding to the provided value interpreted as an unsigned long.static BytesofUnsignedShort(int value) Return a 2-byte value corresponding to the provided value interpreted as an unsigned short.static BytesofUnsignedShort(int value, ByteOrder order) Return a 2-byte value corresponding to the provided value interpreted as an unsigned short.default BytesReturn a bit-wise OR of these bytes and the supplied bytes.default <T extends MutableBytes>
TCalculate a bit-wise OR of these bytes and the supplied bytes.static Bytesrandom(int size) Generate random bytes.static BytesGenerate random bytes.static Bytesrepeat(byte b, int size) Generate a bytes object filled with the same byte.default Bytesreverse()Computes the reverse array of bytes of the current bytes.static Bytessecure(byte[] value) Wrap the provided byte array as aBytesvalue, encrypted in memory.static Bytessecure(byte[] value, int offset, int length) Wrap a slice of a byte array as aBytesvalue, encrypted in memory.static Bytes32[]Splits a Bytes object into Bytes32 objects.default BytesshiftLeft(int distance) Shift all bits in this value to the left.default <T extends MutableBytes>
TshiftLeft(int distance, T result) Shift all bits in this value to the left.default BytesshiftRight(int distance) Shift all bits in this value to the right.default <T extends MutableBytes>
TshiftRight(int distance, T result) Shift all bits in this value to the right.intsize()Provides the number of bytes this value represents.default Bytesslice(int i) Create a new value representing (a view of) a slice of the bytes of this value.slice(int i, int length) Create a new value representing (a view of) a slice of the bytes of this value.default byte[]toArray()Extract the bytes of this value into a byte array.default byte[]Extract the bytes of this value into a byte array.default byte[]Get the bytes represented by this value as byte array.default StringProvides this value represented as base 64default BigIntegerThe BigInteger corresponding to interpreting these bytes as a two's-complement signed integer.default BigIntegertoBigInteger(ByteOrder order) The BigInteger corresponding to interpreting these bytes as a two's-complement signed integer.default Stringdefault StringtoFastHex(boolean prefix) default StringProvides this value represented as hexadecimal, starting with "0x".default inttoInt()The value corresponding to interpreting these bytes as an integer.default intThe value corresponding to interpreting these bytes as an integer.default longtoLong()The value corresponding to interpreting these bytes as a long.default longThe value corresponding to interpreting these bytes as a long.default StringProvides 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).default StringProvides this value represented as a minimal hexadecimal string (without any leading zero)toString()Return the hexadecimal string representation of this value.default StringProvides this value represented as hexadecimal, with no prefixdefault BigIntegerThe BigInteger corresponding to interpreting these bytes as an unsigned integer.default BigIntegertoUnsignedBigInteger(ByteOrder order) The BigInteger corresponding to interpreting these bytes as an unsigned integer.default BytesReturn a slice of representing the same value but without any leading zero bytes.default BytesReturn a slice of representing the same value but without any trailing zero bytes.default voidupdate(MessageDigest digest) Update the provided message digest with the bytes of this value.static Byteswrap(byte[] value) Wrap the provided byte array as aBytesvalue.static Byteswrap(byte[] value, int offset, int length) Wrap a slice of a byte array as aBytesvalue.static BytesWrap a list of other values into a concatenated view.static BytesWrap a list of other values into a concatenated view.static ByteswrapBuffer(io.vertx.core.buffer.Buffer buffer) Wrap a full Vert.xBufferas aBytesvalue.static ByteswrapBuffer(io.vertx.core.buffer.Buffer buffer, int offset, int size) Wrap a slice of a Vert.xBufferas aBytesvalue.static ByteswrapByteBuf(io.netty.buffer.ByteBuf byteBuf) Wrap a full NettyByteBufas aBytesvalue.static ByteswrapByteBuf(io.netty.buffer.ByteBuf byteBuf, int offset, int size) Wrap a slice of a NettyByteBufas aBytesvalue.static ByteswrapByteBuffer(ByteBuffer byteBuffer) Wrap a full Java NIOByteBufferas aBytesvalue.static ByteswrapByteBuffer(ByteBuffer byteBuffer, int offset, int size) Wrap a slice of a Java NIOByteBufas aBytesvalue.default BytesReturn a bit-wise XOR of these bytes and the supplied bytes.default <T extends MutableBytes>
TCalculate a bit-wise XOR of these bytes and the supplied bytes.
-
Field Details
-
EMPTY
The empty value (with 0 bytes).
-
-
Method Details
-
wrap
Wrap the provided byte array as aBytesvalue.Note that value is not copied and thus any future update to
valuewill be reflected in the returned value.- Parameters:
value- The value to wrap.- Returns:
- A
Bytesvalue wrappingvalue.
-
wrap
Wrap a slice of a byte array as aBytesvalue.Note that value is not copied and thus any future update to
valuewithin the slice will be reflected in the returned value.- Parameters:
value- The value to wrap.offset- The index (inclusive) invalueof the first byte exposed by the returned value. In other words, you will havewrap(value, o, l).get(0) == value[o].length- The length of the resulting value.- Returns:
- A
Bytesvalue that expose the bytes ofvaluefromoffset(inclusive) tooffset + length(exclusive). - Throws:
IndexOutOfBoundsException- ifoffset < 0 || (value.length > 0 && offset >= value.length).IllegalArgumentException- iflength < 0 || offset + length > value.length.
-
secure
Wrap the provided byte array as aBytesvalue, encrypted in memory.- Parameters:
value- The value to secure.- Returns:
- A
Bytesvalue securingvalue.
-
secure
Wrap a slice of a byte array as aBytesvalue, encrypted in memory.- Parameters:
value- The value to secure.offset- The index (inclusive) invalueof the first byte exposed by the returned value. In other words, you will havewrap(value, o, l).get(0) == value[o].length- The length of the resulting value.- Returns:
- A
Bytesvalue that holds securely the bytes ofvaluefromoffset(inclusive) tooffset + length(exclusive). - Throws:
IndexOutOfBoundsException- ifoffset < 0 || (value.length > 0 && offset >= value.length).IllegalArgumentException- iflength < 0 || offset + length > value.length.
-
wrap
Wrap a list of other values into a concatenated view.Note that the values are not copied and thus any future update to the values will be reflected in the returned value. If copying the inputs is desired, use
concatenate(Bytes...).- Parameters:
values- The values to wrap.- Returns:
- A value representing a view over the concatenation of all
values. - Throws:
IllegalArgumentException- if the result overflows an int.
-
wrap
Wrap a list of other values into a concatenated view.Note that the values are not copied and thus any future update to the values will be reflected in the returned value. If copying the inputs is desired, use
concatenate(Bytes...).- Parameters:
values- The values to wrap.- Returns:
- A value representing a view over the concatenation of all
values. - Throws:
IllegalArgumentException- if the result overflows an int.
-
concatenate
Create a value containing the concatenation of the values provided.- Parameters:
values- The values to copy and concatenate.- Returns:
- A value containing the result of concatenating the value from
valuesin their provided order. - Throws:
IllegalArgumentException- if the result overflows an int.
-
concatenate
Create a value containing the concatenation of the values provided.- Parameters:
values- The values to copy and concatenate.- Returns:
- A value containing the result of concatenating the value from
valuesin their provided order. - Throws:
IllegalArgumentException- if the result overflows an int.
-
wrapBuffer
Wrap a full Vert.xBufferas aBytesvalue.Note that any change to the content of the buffer may be reflected in the returned value.
- Parameters:
buffer- The buffer to wrap.- Returns:
- A
Bytesvalue.
-
wrapBuffer
Wrap a slice of a Vert.xBufferas aBytesvalue.Note that any change to the content of the buffer may be reflected in the returned value.
- Parameters:
buffer- The buffer to wrap.offset- The offset inbufferfrom which to expose the bytes in the returned value. That is,wrapBuffer(buffer, i, 1).get(0) == buffer.getByte(i).size- The size of the returned value.- Returns:
- A
Bytesvalue. - Throws:
IndexOutOfBoundsException- ifoffset < 0 || (buffer.length() > 0 && offset >= buffer.length()).IllegalArgumentException- iflength < 0 || offset + length > buffer.length().
-
wrapByteBuf
Wrap a full NettyByteBufas aBytesvalue.Note that any change to the content of the byteBuf may be reflected in the returned value.
- Parameters:
byteBuf- TheByteBufto wrap.- Returns:
- A
Bytesvalue.
-
wrapByteBuf
Wrap a slice of a NettyByteBufas aBytesvalue.Note that any change to the content of the buffer may be reflected in the returned value.
- Parameters:
byteBuf- TheByteBufto wrap.offset- The offset inbyteBuffrom which to expose the bytes in the returned value. That is,wrapByteBuf(byteBuf, i, 1).get(0) == byteBuf.getByte(i).size- The size of the returned value.- Returns:
- A
Bytesvalue. - Throws:
IndexOutOfBoundsException- ifoffset < 0 || (byteBuf.capacity() > 0 && offset >= byteBuf.capacity()).IllegalArgumentException- iflength < 0 || offset + length > byteBuf.capacity().
-
wrapByteBuffer
Wrap a full Java NIOByteBufferas aBytesvalue.Note that any change to the content of the byteBuf may be reflected in the returned value.
- Parameters:
byteBuffer- TheByteBufferto wrap.- Returns:
- A
Bytesvalue.
-
wrapByteBuffer
Wrap a slice of a Java NIOByteBufas aBytesvalue.Note that any change to the content of the buffer may be reflected in the returned value.
- Parameters:
byteBuffer- TheByteBufferto wrap.offset- The offset inbyteBufferfrom which to expose the bytes in the returned value. That is,wrapByteBuffer(byteBuffer, i, 1).get(0) == byteBuffer.getByte(i).size- The size of the returned value.- Returns:
- A
Bytesvalue. - Throws:
IndexOutOfBoundsException- ifoffset < 0 || (byteBuffer.limit() > 0 && offset >= byteBuf.limit()).IllegalArgumentException- iflength < 0 || offset + length > byteBuffer.limit().
-
of
Create a value that contains the specified bytes in their specified order.- Parameters:
bytes- The bytes that must compose the returned value.- Returns:
- A value containing the specified bytes.
-
of
Create a value that contains the specified bytes in their specified order.- Parameters:
bytes- The bytes.- Returns:
- A value containing bytes are the one from
bytes. - Throws:
IllegalArgumentException- if any of the specified would be truncated when storing as a byte.
-
ofUnsignedShort
Return a 2-byte value corresponding to the provided value interpreted as an unsigned short.- Parameters:
value- The value, which must be no larger than an unsigned short.- Returns:
- A 2 bytes value corresponding to
value. - Throws:
IllegalArgumentException- ifvalue < 0orvalueis too big to fit an unsigned 2-byte short (that is, ifvalue >= (1 << 16)).
-
ofUnsignedShort
Return a 2-byte value corresponding to the provided value interpreted as an unsigned short.- Parameters:
value- The value, which must be no larger than an unsigned short.order- The byte-order for the integer encoding.- Returns:
- A 2 bytes value corresponding to
value. - Throws:
IllegalArgumentException- ifvalue < 0orvalueis too big to fit an unsigned 2-byte short (that is, ifvalue >= (1 << 16)).
-
ofUnsignedInt
Return a 4-byte value corresponding to the provided value interpreted as an unsigned int.- Parameters:
value- The value, which must be no larger than an unsigned int.- Returns:
- A 4 bytes value corresponding to
value. - Throws:
IllegalArgumentException- ifvalue < 0orvalueis too big to fit an unsigned 4-byte int (that is, ifvalue >= (1L << 32)).
-
ofUnsignedInt
Return a 4-byte value corresponding to the provided value interpreted as an unsigned int.- Parameters:
value- The value, which must be no larger than an unsigned int.order- The byte-order for the integer encoding.- Returns:
- A 4 bytes value corresponding to the encoded
value. - Throws:
IllegalArgumentException- ifvalue < 0orvalueis too big to fit an unsigned 4-byte int (that is, ifvalue >= (1L << 32)).
-
ofUnsignedLong
Return an 8-byte value corresponding to the provided value interpreted as an unsigned long.- Parameters:
value- The value, which will be interpreted as an unsigned long.- Returns:
- A 8 bytes value corresponding to
value. - Throws:
IllegalArgumentException- ifvalue < 0orvalueis too big to fit an unsigned 8-byte int (that is, ifvalue >= (1L << 64)).
-
ofUnsignedLong
Return an 8-byte value corresponding to the provided value interpreted as an unsigned long.- Parameters:
value- The value, which will be interpreted as an unsigned long.order- The byte-order for the integer encoding.- Returns:
- A 8 bytes value corresponding to
value. - Throws:
IllegalArgumentException- ifvalue < 0orvalueis too big to fit an unsigned 8-byte int (that is, ifvalue >= (1L << 64)).
-
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.- Parameters:
value- The long from which to create the bytes value.- Returns:
- The minimal bytes representation corresponding to
l.
-
fromHexStringLenient
Parse a hexadecimal string into aBytesvalue.This method is lenient in that
strmay of an odd length, in which case it will behave exactly as if it had an additional 0 in front.- Parameters:
str- The hexadecimal string to parse, which may or may not start with "0x".- Returns:
- The value corresponding to
str. - Throws:
IllegalArgumentException- ifstrdoes not correspond to a valid hexadecimal representation.
-
fromHexStringLenient
Parse a hexadecimal string into aBytesvalue of the provided size.This method allows for
strto have an odd length, in which case it will behave exactly as if it had an additional 0 in front.- Parameters:
str- The hexadecimal string to parse, which may or may not start with "0x".destinationSize- The size of the returned value, which must be big enough to hold the bytes represented bystr. If it is strictly bigger those bytes fromstr, the returned value will be left padded with zeros.- Returns:
- A value of size
destinationSizecorresponding tostrpotentially left-padded. - Throws:
IllegalArgumentException- ifstrdoes not correspond to a valid hexadecimal representation, represents more bytes thandestinationSizeordestinationSize < 0.
-
fromHexString
Parse a hexadecimal string into aBytesvalue.This method requires that
strhave an even length.- Parameters:
str- The hexadecimal string to parse, which may or may not start with "0x".- Returns:
- The value corresponding to
str. - Throws:
IllegalArgumentException- ifstrdoes not correspond to a valid hexadecimal representation, or is of an odd length.
-
fromHexString
Parse a hexadecimal string into aBytesvalue.This method requires that
strhave an even length.- Parameters:
str- The hexadecimal string to parse, which may or may not start with "0x".destinationSize- The size of the returned value, which must be big enough to hold the bytes represented bystr. If it is strictly bigger those bytes fromstr, the returned value will be left padded with zeros.- Returns:
- A value of size
destinationSizecorresponding tostrpotentially left-padded. - Throws:
IllegalArgumentException- ifstrdoes correspond to a valid hexadecimal representation, or is of an odd length.IllegalArgumentException- ifstrdoes not correspond to a valid hexadecimal representation, or is of an odd length, or represents more bytes thandestinationSizeordestinationSize < 0.
-
fromBase64String
Parse a base 64 string into aBytesvalue.- Parameters:
str- The base 64 string to parse.- Returns:
- The value corresponding to
str.
-
random
Generate random bytes.- Parameters:
size- The number of bytes to generate.- Returns:
- A value containing the desired number of random bytes.
-
random
Generate random bytes.- Parameters:
size- The number of bytes to generate.generator- The generator for random bytes.- Returns:
- A value containing the desired number of random bytes.
-
repeat
Generate a bytes object filled with the same byte.- Parameters:
b- the byte to fill the Bytes withsize- the size of the object- Returns:
- a value filled with a fixed byte
-
segment
Splits a Bytes object into Bytes32 objects. If the last element is not exactly 32 bytes, it is right padded with zeros.- Parameters:
bytes- the bytes object to segment- Returns:
- an array of Bytes32 objects
-
size
int size()Provides the number of bytes this value represents.- Returns:
- The number of bytes this value represents.
-
get
byte get(int i) Retrieve a byte in this value.- Parameters:
i- The index of the byte to fetch within the value (0-indexed).- Returns:
- The byte at index
iin this value. - Throws:
IndexOutOfBoundsException- ifi < 0or {i >= size()}.
-
getInt
default int getInt(int i) Retrieve the 4 bytes starting at the provided index in this value as an integer.- Parameters:
i- The index from which to get the int, which must less than or equal tosize() - 4.- Returns:
- An integer whose value is the 4 bytes from this value starting at index
i. - Throws:
IndexOutOfBoundsException- ifi < 0ori > size() - 4.
-
getInt
Retrieve the 4 bytes starting at the provided index in this value as an integer.- Parameters:
i- The index from which to get the int, which must less than or equal tosize() - 4.order- The byte-order for decoding the integer.- Returns:
- An integer whose value is the 4 bytes from this value starting at index
i. - Throws:
IndexOutOfBoundsException- ifi < 0ori > size() - 4.
-
toInt
default int toInt()The value corresponding to interpreting these bytes as an integer.- Returns:
- An value corresponding to this value interpreted as an integer.
- Throws:
IllegalArgumentException- ifsize() > 4.
-
toInt
The value corresponding to interpreting these bytes as an integer.- Parameters:
order- The byte-order for decoding the integer.- Returns:
- An value corresponding to this value interpreted as an integer.
- Throws:
IllegalArgumentException- ifsize() > 4.
-
isEmpty
default boolean isEmpty()Whether this value contains no bytes.- Returns:
- true if the value contains no bytes
-
getLong
default long getLong(int i) Retrieves the 8 bytes starting at the provided index in this value as a long.- Parameters:
i- The index from which to get the long, which must less than or equal tosize() - 8.- Returns:
- A long whose value is the 8 bytes from this value starting at index
i. - Throws:
IndexOutOfBoundsException- ifi < 0ori > size() - 8.
-
getLong
Retrieves the 8 bytes starting at the provided index in this value as a long.- Parameters:
i- The index from which to get the long, which must less than or equal tosize() - 8.order- The byte-order for decoding the integer.- Returns:
- A long whose value is the 8 bytes from this value starting at index
i. - Throws:
IndexOutOfBoundsException- ifi < 0ori > size() - 8.
-
toLong
default long toLong()The value corresponding to interpreting these bytes as a long.- Returns:
- An value corresponding to this value interpreted as a long.
- Throws:
IllegalArgumentException- ifsize() > 8.
-
toLong
The value corresponding to interpreting these bytes as a long.- Parameters:
order- The byte-order for decoding the integer.- Returns:
- An value corresponding to this value interpreted as a long.
- Throws:
IllegalArgumentException- ifsize() > 8.
-
toBigInteger
The BigInteger corresponding to interpreting these bytes as a two's-complement signed integer.- Returns:
- A
BigIntegercorresponding to interpreting these bytes as a two's-complement signed integer.
-
toBigInteger
The BigInteger corresponding to interpreting these bytes as a two's-complement signed integer.- Parameters:
order- The byte-order for decoding the integer.- Returns:
- A
BigIntegercorresponding to interpreting these bytes as a two's-complement signed integer.
-
toUnsignedBigInteger
The BigInteger corresponding to interpreting these bytes as an unsigned integer.- Returns:
- A positive (or zero)
BigIntegercorresponding to interpreting these bytes as an unsigned integer.
-
toUnsignedBigInteger
The BigInteger corresponding to interpreting these bytes as an unsigned integer.- Parameters:
order- The byte-order for decoding the integer.- Returns:
- A positive (or zero)
BigIntegercorresponding to interpreting these bytes as an unsigned integer.
-
isZero
default boolean isZero()Whether this value has only zero bytes.- Returns:
trueif all the bits of this value are zeros.
-
hasLeadingZero
default boolean hasLeadingZero()Whether the bytes start with a zero bit value.- Returns:
- true if the first bit equals zero
-
numberOfLeadingZeros
default int numberOfLeadingZeros()Provides the number of zero bits preceding the highest-order ("leftmost") one-bit, orsize() * 8if all bits * are zero.- Returns:
- The number of zero bits preceding the highest-order ("leftmost") one-bit, or
size() * 8if all bits are zero.
-
hasLeadingZeroByte
default boolean hasLeadingZeroByte()Whether the bytes start with a zero byte value.- Returns:
- true if the first byte equals zero
-
numberOfLeadingZeroBytes
default int numberOfLeadingZeroBytes()Provides the number of leading zero bytes of the value- Returns:
- The number of leading zero bytes of the value.
-
numberOfTrailingZeroBytes
default int numberOfTrailingZeroBytes()Provides the number of trailing zero bytes of the value.- Returns:
- The number of trailing zero bytes of the value.
-
bitLength
default int bitLength()Provides the number of bits following and including the highest-order ("leftmost") one-bit, or zero if all bits are zero.- Returns:
- The number of bits following and including the highest-order ("leftmost") one-bit, or zero if all bits are zero.
-
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.
- Parameters:
other- The bytes to perform the operation with.- Returns:
- The result of a bit-wise AND.
-
and
Calculate a bit-wise AND of these bytes and the supplied bytes.If this value or the supplied value are shorter in length than the output vector, then they will be zero-padded to the left. Likewise, if either this value or the supplied valid is longer in length than the output vector, then they will be truncated to the left.
- Type Parameters:
T- TheMutableBytesvalue type.- Parameters:
other- The bytes to perform the operation with.result- The mutable output vector for the result.- Returns:
- The
resultoutput vector.
-
or
Return a bit-wise OR 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.
- Parameters:
other- The bytes to perform the operation with.- Returns:
- The result of a bit-wise OR.
-
or
Calculate a bit-wise OR of these bytes and the supplied bytes.If this value or the supplied value are shorter in length than the output vector, then they will be zero-padded to the left. Likewise, if either this value or the supplied valid is longer in length than the output vector, then they will be truncated to the left.
- Type Parameters:
T- TheMutableBytesvalue type.- Parameters:
other- The bytes to perform the operation with.result- The mutable output vector for the result.- Returns:
- The
resultoutput vector.
-
xor
Return a bit-wise XOR 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.
- Parameters:
other- The bytes to perform the operation with.- Returns:
- The result of a bit-wise XOR.
-
xor
Calculate a bit-wise XOR of these bytes and the supplied bytes.If this value or the supplied value are shorter in length than the output vector, then they will be zero-padded to the left. Likewise, if either this value or the supplied valid is longer in length than the output vector, then they will be truncated to the left.
- Type Parameters:
T- TheMutableBytesvalue type.- Parameters:
other- The bytes to perform the operation with.result- The mutable output vector for the result.- Returns:
- The
resultoutput vector.
-
not
Return a bit-wise NOT of these bytes.- Returns:
- The result of a bit-wise NOT.
-
not
Calculate a bit-wise NOT of these bytes.If this value is shorter in length than the output vector, then it will be zero-padded to the left. Likewise, if this value is longer in length than the output vector, then it will be truncated to the left.
- Type Parameters:
T- TheMutableBytesvalue type.- Parameters:
result- The mutable output vector for the result.- Returns:
- The
resultoutput vector.
-
shiftRight
Shift all bits in this value to the right.- Parameters:
distance- The number of bits to shift by.- Returns:
- A value containing the shifted bits.
-
shiftRight
Shift all bits in this value to the right.If this value is shorter in length than the output vector, then it will be zero-padded to the left. Likewise, if this value is longer in length than the output vector, then it will be truncated to the left (after shifting).
- Type Parameters:
T- TheMutableBytesvalue type.- Parameters:
distance- The number of bits to shift by.result- The mutable output vector for the result.- Returns:
- The
resultoutput vector.
-
shiftLeft
Shift all bits in this value to the left.- Parameters:
distance- The number of bits to shift by.- Returns:
- A value containing the shifted bits.
-
shiftLeft
Shift all bits in this value to the left.If this value is shorter in length than the output vector, then it will be zero-padded to the left. Likewise, if this value is longer in length than the output vector, then it will be truncated to the left.
- Type Parameters:
T- TheMutableBytesvalue type.- Parameters:
distance- The number of bits to shift by.result- The mutable output vector for the result.- Returns:
- The
resultoutput vector.
-
slice
Create a new value representing (a view of) a slice of the bytes of this value.Please note that the resulting slice is only a view and as such maintains a link to the underlying full value. So holding a reference to the returned slice may hold more memory than the slide represents. Use
copy()on the returned slice if that is not what you want.- Parameters:
i- The start index for the slice.- Returns:
- A new value providing a view over the bytes from index
i(included) to the end. - Throws:
IndexOutOfBoundsException- ifi < 0.
-
slice
Create a new value representing (a view of) a slice of the bytes of this value.Please note that the resulting slice is only a view and as such maintains a link to the underlying full value. So holding a reference to the returned slice may hold more memory than the slide represents. Use
copy()on the returned slice if that is not what you want.- Parameters:
i- The start index for the slice.length- The length of the resulting value.- Returns:
- A new value providing a view over the bytes from index
i(included) toi + length(excluded). - Throws:
IllegalArgumentException- iflength < 0.IndexOutOfBoundsException- ifi < 0or {i >= size()} or {i + length > size()} .
-
copy
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.- Returns:
- A value, equals to this one, but deeply immutable and that doesn't retain any "unreachable" bytes. For performance reasons, this is allowed to return this value however if it already fit those constraints.
-
mutableCopy
MutableBytes mutableCopy()Return a new mutable value initialized with the content of this value.- Returns:
- A mutable copy of this value. This will copy bytes, modifying the returned value will not modify this value.
-
copyTo
Copy the bytes of this value to the provided mutable one, which must have the same size.- Parameters:
destination- The mutable value to which to copy the bytes to, which must have the same size as this value. If you want to copy value where size differs, you should useslice(int)and/orMutableBytes.mutableSlice(int, int)and apply the copy to the result.- Throws:
IllegalArgumentException- ifthis.size() != destination.size().
-
copyTo
Copy the bytes of this value to the provided mutable one from a particular offset.This is a (potentially slightly more efficient) shortcut for
copyTo(destination.mutableSlice(destinationOffset, this.size())).- Parameters:
destination- The mutable value to which to copy the bytes to, which must have enough bytes fromdestinationOffsetfor the copied value.destinationOffset- The offset indestinationat which the copy starts.- Throws:
IllegalArgumentException- if the destination doesn't have enough room, that is ifthis.size() > (destination.size() - destinationOffset).
-
appendTo
Append the bytes of this value to theByteBuffer.- Parameters:
byteBuffer- TheByteBufferto which to append this value.- Throws:
BufferOverflowException- If the writer attempts to write more than the provided buffer can hold.ReadOnlyBufferException- If the provided buffer is read-only.
-
appendTo
default void appendTo(io.vertx.core.buffer.Buffer buffer) Append the bytes of this value to the provided Vert.xBuffer.Note that since a Vert.x
Bufferwill grow as necessary, this method never fails.- Parameters:
buffer- TheBufferto which to append this value.
-
appendHexTo
Append this value as a sequence of hexadecimal characters.- Type Parameters:
T- The appendable type.- Parameters:
appendable- The appendable- Returns:
- The appendable.
-
toFastHex
-
commonPrefixLength
Return the number of bytes in common between this set of bytes and another.- Parameters:
other- The bytes to compare to.- Returns:
- The number of common bytes.
-
commonPrefix
Return a slice over the common prefix between this set of bytes and another.- Parameters:
other- The bytes to compare to.- Returns:
- A slice covering the common prefix.
-
trimLeadingZeros
Return a slice of representing the same value but without any leading zero bytes.- Returns:
valueif its left-most byte is non zero, or a slice that exclude any leading zero bytes.
-
trimTrailingZeros
Return a slice of representing the same value but without any trailing zero bytes.- Returns:
valueif its right-most byte is non zero, or a slice that exclude any trailing zero bytes.
-
update
Update the provided message digest with the bytes of this value.- Parameters:
digest- The digest to update.
-
reverse
Computes the reverse array of bytes of the current bytes.- Returns:
- a new Bytes value, containing the bytes in reverse order
-
toArray
default byte[] toArray()Extract the bytes of this value into a byte array.- Returns:
- A byte array with the same content than this value.
-
toArray
Extract the bytes of this value into a byte array.- Parameters:
byteOrder- the byte order to apply : big endian or little endian- Returns:
- A byte array with the same content than this value.
-
toArrayUnsafe
default byte[] toArrayUnsafe()Get the bytes represented by this value as byte array.Contrarily to
toArray(), this may avoid allocating a new array and directly return the backing array of this value if said value is array backed and doing so is possible. As such, modifications to the returned array may or may not impact this value. As such, this method should be used with care and hence the "unsafe" moniker.- Returns:
- A byte array with the same content than this value, which may or may not be the direct backing of this value.
-
toString
String toString()Return the hexadecimal string representation of this value. -
toHexString
Provides this value represented as hexadecimal, starting with "0x".- Returns:
- This value represented as hexadecimal, starting with "0x".
-
toUnprefixedHexString
Provides this value represented as hexadecimal, with no prefix- Returns:
- This value represented as hexadecimal, with no prefix.
-
toEllipsisHexString
-
toShortHexString
Provides this value represented as a minimal hexadecimal string (without any leading zero)- Returns:
- This value represented as a minimal hexadecimal string (without any leading zero).
-
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).- Returns:
- 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).
-
toBase64String
Provides this value represented as base 64- Returns:
- This value represented as base 64.
-
compareTo
- Specified by:
compareToin interfaceComparable<Bytes>
-