Interface Bytes48
- All Superinterfaces:
Bytes,Comparable<Bytes>
- All Known Subinterfaces:
MutableBytes48
- All Known Implementing Classes:
DelegatingBytes48
Bytes value that is guaranteed to contain exactly 48 bytes.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe number of bytes in this value - i.e.static final Bytes48ABytes48containing all zero bytes -
Method Summary
Modifier and TypeMethodDescriptiondefault Bytes48Return 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 Bytes48Parse a hexadecimal string into aBytes48.static Bytes48Parse a hexadecimal string into aBytes48.static Bytes48Parse a hexadecimal string into aBytes48.static Bytes48Return a new mutable value initialized with the content of this value.default Bytes48not()Return a bit-wise NOT of these bytes.default Bytes48Return a bit-wise OR of these bytes and the supplied bytes.static Bytes48random()Generate random bytes.static Bytes48Generate random bytes.static Bytes48default Bytes48shiftLeft(int distance) Shift all bits in this value to the left.default Bytes48shiftRight(int distance) Shift all bits in this value to the right.default intsize()Provides the number of bytes this value represents.static Bytes48wrap(byte[] bytes) Wrap the provided byte array, which must be of length 48, as aBytes48.static Bytes48wrap(byte[] bytes, int offset) Wrap a slice/sub-part of the provided array as aBytes48.static Bytes48Wrap a the provided value, which must be of size 48, as aBytes48.static Bytes48Wrap a slice/sub-part of the provided value as aBytes48.default Bytes48Return 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. 48- See Also:
-
ZERO
ABytes48containing all zero bytes
-
-
Method Details
-
wrap
Wrap the provided byte array, which must be of length 48, as aBytes48.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
Bytes48wrappingvalue. - Throws:
IllegalArgumentException- ifvalue.length != 48.
-
wrap
Wrap a slice/sub-part of the provided array as aBytes48.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
Bytes48that exposes the bytes ofvaluefromoffset(inclusive) tooffset + 48(exclusive). - Throws:
IndexOutOfBoundsException- ifoffset < 0 || (value.length > 0 && offset >= value.length).IllegalArgumentException- iflength < 0 || offset + 48 > value.length.
-
wrap
Wrap a the provided value, which must be of size 48, as aBytes48.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
Bytes48that exposes the bytes ofvalue. - Throws:
IllegalArgumentException- ifvalue.size() != 48.
-
wrap
Wrap a slice/sub-part of the provided value as aBytes48.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
Bytes48that exposes the bytes ofvaluefromoffset(inclusive) tooffset + 48(exclusive). - Throws:
IndexOutOfBoundsException- ifoffset < 0 || (value.size() > 0 && offset >= value.size()).IllegalArgumentException- iflength < 0 || offset + 48 > value.size().
-
leftPad
- Parameters:
value- The bytes value pad.- Returns:
- A
Bytes48that exposes the left-padded bytes ofvalue. - Throws:
IllegalArgumentException- ifvalue.size() > 48.
-
rightPad
- Parameters:
value- The bytes value pad.- Returns:
- A
Bytes48that exposes the rightw-padded bytes ofvalue. - Throws:
IllegalArgumentException- ifvalue.size() > 48.
-
fromHexStringLenient
Parse a hexadecimal string into aBytes48.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 48 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 48 bytes.
-
fromHexString
Parse a hexadecimal string into aBytes48.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 48 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 48 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 aBytes48.This method is extra strict in that
strmust of an even length and the provided representation must have exactly 48 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 48 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
Bytes48 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
MutableBytes48 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.
-