Interface Bytes32
- All Superinterfaces:
Bytes,Comparable<Bytes>
- All Known Subinterfaces:
MutableBytes32
- All Known Implementing Classes:
DelegatingBytes32
Bytes value that is guaranteed to contain exactly 32 bytes.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe number of bytes in this value - i.e.static final Bytes32ABytes32containing all zero bytes -
Method Summary
Modifier and TypeMethodDescriptiondefault Bytes32Return a bit-wise AND of these bytes and the supplied bytes.copy()Return a value equivalent to this one but guaranteed to 1) be deeply immutable (i.e.static Bytes32Parse a hexadecimal string into aBytes32.static Bytes32Parse a hexadecimal string into aBytes32.static Bytes32Parse a hexadecimal string into aBytes32.static Bytes32static Bytes32Return a new mutable value initialized with the content of this value.default Bytes32not()Return a bit-wise NOT of these bytes.default Bytes32Return a bit-wise OR of these bytes and the supplied bytes.static Bytes32random()Generate random bytes.static Bytes32Generate random bytes.static Bytes32repeat(byte b) Generate a bytes object filled with the same byte.static Bytes32static Bytes32secure(byte[] bytes) Secures the provided byte array, which must be of length 32, as aBytes32.static Bytes32secure(byte[] bytes, int offset) Secures a slice/sub-part of the provided array as aBytes32.default Bytes32shiftLeft(int distance) Shift all bits in this value to the left.default Bytes32shiftRight(int distance) Shift all bits in this value to the right.default intsize()Provides the number of bytes this value represents.static Bytes32wrap(byte[] bytes) Wrap the provided byte array, which must be of length 32, as aBytes32.static Bytes32wrap(byte[] bytes, int offset) Wrap a slice/sub-part of the provided array as aBytes32.static Bytes32Wrap a the provided value, which must be of size 32, as aBytes32.static Bytes32Wrap a slice/sub-part of the provided value as aBytes32.default Bytes32Return a bit-wise XOR of these bytes and the supplied bytes.Methods inherited from interface org.apache.tuweni.bytes.Bytes
and, and, appendHexTo, appendTo, appendTo, bitLength, commonPrefix, commonPrefixLength, compareTo, copyTo, copyTo, get, getInt, getInt, getLong, getLong, hasLeadingZero, hasLeadingZeroByte, isEmpty, isZero, not, numberOfLeadingZeroBytes, numberOfLeadingZeros, numberOfTrailingZeroBytes, or, or, reverse, shiftLeft, shiftRight, slice, slice, toArray, toArray, toArrayUnsafe, toBase64String, toBigInteger, toBigInteger, toEllipsisHexString, toFastHex, toHexString, toInt, toInt, toLong, toLong, toQuantityHexString, toShortHexString, toString, toUnprefixedHexString, toUnsignedBigInteger, toUnsignedBigInteger, trimLeadingZeros, trimTrailingZeros, update, xor, xor
-
Field Details
-
SIZE
static final int SIZEThe number of bytes in this value - i.e. 32- See Also:
-
ZERO
ABytes32containing all zero bytes
-
-
Method Details
-
repeat
Generate a bytes object filled with the same byte.- Parameters:
b- the byte to fill the Bytes with- Returns:
- a value filled with a fixed byte
-
wrap
Wrap the provided byte array, which must be of length 32, as aBytes32.Note that value is not copied, only wrapped, and thus any future update to
valuewill be reflected in the returned value.- Parameters:
bytes- The bytes to wrap.- Returns:
- A
Bytes32wrappingvalue. - Throws:
IllegalArgumentException- ifvalue.length != 32.
-
wrap
Wrap a slice/sub-part of the provided array as aBytes32.Note that value is not copied, only wrapped, and thus any future update to
valuewithin the wrapped parts will be reflected in the returned value.- Parameters:
bytes- The bytes to wrap.offset- The index (inclusive) invalueof the first byte exposed by the returned value. In other words, you will havewrap(value, i).get(0) == value[i].- Returns:
- A
Bytes32that exposes the bytes ofvaluefromoffset(inclusive) tooffset + 32(exclusive). - Throws:
IndexOutOfBoundsException- ifoffset < 0 || (value.length > 0 && offset >= value.length).IllegalArgumentException- iflength < 0 || offset + 32 > value.length.
-
secure
Secures the provided byte array, which must be of length 32, as aBytes32.- Parameters:
bytes- The bytes to secure.- Returns:
- A
Bytes32securingvalue. - Throws:
IllegalArgumentException- ifvalue.length != 32.
-
secure
Secures a slice/sub-part of the provided array as aBytes32.- Parameters:
bytes- The bytes to secure.offset- The index (inclusive) invalueof the first byte exposed by the returned value. In other words, you will havewrap(value, i).get(0) == value[i].- Returns:
- A
Bytes32that holds securely the bytes ofvaluefromoffset(inclusive) tooffset + 32(exclusive). - Throws:
IndexOutOfBoundsException- ifoffset < 0 || (value.length > 0 && offset >= value.length).IllegalArgumentException- iflength < 0 || offset + 32 > value.length.
-
wrap
Wrap a the provided value, which must be of size 32, as aBytes32.Note that value is not copied, only wrapped, and thus any future update to
valuewill be reflected in the returned value.- Parameters:
value- The bytes to wrap.- Returns:
- A
Bytes32that exposes the bytes ofvalue. - Throws:
IllegalArgumentException- ifvalue.size() != 32.
-
wrap
Wrap a slice/sub-part of the provided value as aBytes32.Note that value is not copied, only wrapped, and thus any future update to
valuewithin the wrapped parts will be reflected in the returned value.- Parameters:
value- The bytes to wrap.offset- The index (inclusive) invalueof the first byte exposed by the returned value. In other words, you will havewrap(value, i).get(0) == value.get(i).- Returns:
- A
Bytes32that exposes the bytes ofvaluefromoffset(inclusive) tooffset + 32(exclusive). - Throws:
IndexOutOfBoundsException- ifoffset < 0 || (value.size() > 0 && offset >= value.size()).IllegalArgumentException- iflength < 0 || offset + 32 > value.size().
-
leftPad
- Parameters:
value- The bytes value pad.fill- the byte to fill with- Returns:
- A
Bytes32that exposes the left-padded bytes ofvalue. - Throws:
IllegalArgumentException- ifvalue.size() > 32.
-
leftPad
- Parameters:
value- The bytes value pad.- Returns:
- A
Bytes32that exposes the left-padded bytes ofvalue. - Throws:
IllegalArgumentException- ifvalue.size() > 32.
-
rightPad
- Parameters:
value- The bytes value pad.- Returns:
- A
Bytes32that exposes the rightw-padded bytes ofvalue. - Throws:
IllegalArgumentException- ifvalue.size() > 32.
-
fromHexStringLenient
Parse a hexadecimal string into aBytes32.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". That representation may contain less than 32 bytes, in which case the result is left padded with zeros (seefromHexStringStrict(java.lang.CharSequence)if this is not what you want).- Returns:
- The value corresponding to
str. - Throws:
IllegalArgumentException- ifstrdoes not correspond to a valid hexadecimal representation or contains more than 32 bytes.
-
fromHexString
Parse a hexadecimal string into aBytes32.This method is strict in that
strmust of an even length.- Parameters:
str- The hexadecimal string to parse, which may or may not start with "0x". That representation may contain less than 32 bytes, in which case the result is left padded with zeros (seefromHexStringStrict(java.lang.CharSequence)if this is not what you want).- Returns:
- The value corresponding to
str. - Throws:
IllegalArgumentException- ifstrdoes not correspond to a valid hexadecimal representation, is of an odd length, or contains more than 32 bytes.
-
random
Generate random bytes.- Returns:
- A value containing random bytes.
-
random
Generate random bytes.- Parameters:
generator- The generator for random bytes.- Returns:
- A value containing random bytes.
-
fromHexStringStrict
Parse a hexadecimal string into aBytes32.This method is extra strict in that
strmust of an even length and the provided representation must have exactly 32 bytes.- 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, is of an odd length or does not contain exactly 32 bytes.
-
size
default int size()Description copied from interface:BytesProvides the number of bytes this value represents. -
and
Return a bit-wise AND of these bytes and the supplied bytes.- Parameters:
other- The bytes to perform the operation with.- Returns:
- The result of a bit-wise AND.
-
or
Return a bit-wise OR of these bytes and the supplied bytes.- Parameters:
other- The bytes to perform the operation with.- Returns:
- The result of a bit-wise OR.
-
xor
Return a bit-wise XOR of these bytes and the supplied bytes.- Parameters:
other- The bytes to perform the operation with.- Returns:
- The result of a bit-wise XOR.
-
not
Description copied from interface:BytesReturn a bit-wise NOT of these bytes. -
shiftRight
Description copied from interface:BytesShift all bits in this value to the right.- Specified by:
shiftRightin interfaceBytes- Parameters:
distance- The number of bits to shift by.- Returns:
- A value containing the shifted bits.
-
shiftLeft
Description copied from interface:BytesShift all bits in this value to the left. -
copy
Bytes32 copy()Description copied from interface:BytesReturn 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. -
mutableCopy
MutableBytes32 mutableCopy()Description copied from interface:BytesReturn a new mutable value initialized with the content of this value.- Specified by:
mutableCopyin interfaceBytes- Returns:
- A mutable copy of this value. This will copy bytes, modifying the returned value will not modify this value.
-