Class DelegatingBytes
- All Implemented Interfaces:
Comparable<Bytes>,Bytes
- Direct Known Subclasses:
DelegatingBytes32,DelegatingBytes48
This class may be used to create more types that represent bytes, but need a different name for business logic.
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturn a bit-wise AND of these bytes and the supplied bytes.<T extends MutableBytes>
TCalculate a bit-wise AND of these bytes and the supplied bytes.<T extends Appendable>
TappendHexTo(T appendable) Append this value as a sequence of hexadecimal characters.voidappendTo(io.vertx.core.buffer.Buffer buffer) Append the bytes of this value to the provided Vert.xBuffer.voidappendTo(ByteBuffer byteBuffer) Append the bytes of this value to theByteBuffer.intProvides the number of bits following and including the highest-order ("leftmost") one-bit, or zero if all bits are zero.commonPrefix(Bytes other) Return a slice over the common prefix between this set of bytes and another.intcommonPrefixLength(Bytes other) Return the number of bytes in common between this set of bytes and another.intcopy()Return a value equivalent to this one but guaranteed to 1) be deeply immutable (i.e.voidcopyTo(MutableBytes destination) Copy the bytes of this value to the provided mutable one, which must have the same size.voidcopyTo(MutableBytes destination, int destinationOffset) Copy the bytes of this value to the provided mutable one from a particular offset.booleanCompare this value and the provided one for equality.byteget(int i) Retrieve a byte in this value.intgetInt(int i) Retrieve the 4 bytes starting at the provided index in this value as an integer.intRetrieve the 4 bytes starting at the provided index in this value as an integer.longgetLong(int i) Retrieves the 8 bytes starting at the provided index in this value as a long.longRetrieves the 8 bytes starting at the provided index in this value as a long.inthashCode()booleanWhether the bytes start with a zero bit value.booleanWhether the bytes start with a zero byte value.booleanisEmpty()Whether this value contains no bytes.booleanisZero()Whether this value has only zero bytes.Return a new mutable value initialized with the content of this value.intProvides the number of leading zero bytes of the valueintProvides the number of zero bits preceding the highest-order ("leftmost") one-bit, orsize() * 8if all bits * are zero.intProvides the number of trailing zero bytes of the value.Return a bit-wise OR of these bytes and the supplied bytes.<T extends MutableBytes>
TCalculate a bit-wise OR of these bytes and the supplied bytes.reverse()Computes the reverse array of bytes of the current bytes.<T extends MutableBytes>
TshiftLeft(int distance, T result) Shift all bits in this value to the left.<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.slice(int i) Create a new value representing (a view of) a slice of the bytes of this value.slice(int index, int length) Create a new value representing (a view of) a slice of the bytes of this value.byte[]toArray()Extract the bytes of this value into a byte array.byte[]Extract the bytes of this value into a byte array.byte[]Get the bytes represented by this value as byte array.Provides this value represented as base 64The BigInteger corresponding to interpreting these bytes as a two's-complement signed integer.toBigInteger(ByteOrder order) The BigInteger corresponding to interpreting these bytes as a two's-complement signed integer.Provides this value represented as hexadecimal, starting with "0x".inttoInt()The value corresponding to interpreting these bytes as an integer.intThe value corresponding to interpreting these bytes as an integer.longtoLong()The value corresponding to interpreting these bytes as a long.longThe value corresponding to interpreting these bytes as a long.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).Provides this value represented as a minimal hexadecimal string (without any leading zero)toString()Return the hexadecimal string representation of this value.Provides this value represented as hexadecimal, with no prefixThe BigInteger corresponding to interpreting these bytes as an unsigned integer.toUnsignedBigInteger(ByteOrder order) The BigInteger corresponding to interpreting these bytes as an unsigned integer.Return a slice of representing the same value but without any leading zero bytes.voidupdate(MessageDigest digest) Update the provided message digest with the bytes of this value.Return a bit-wise XOR of these bytes and the supplied bytes.<T extends MutableBytes>
TCalculate a bit-wise XOR of these bytes and the supplied bytes.Methods inherited from class org.apache.tuweni.bytes.AbstractBytes
computeHashcodeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.tuweni.bytes.Bytes
not, not, shiftLeft, shiftRight, toFastHex, trimTrailingZeros
-
Constructor Details
-
DelegatingBytes
-
-
Method Details
-
size
public int size()Description copied from interface:BytesProvides the number of bytes this value represents. -
get
public byte get(int i) Description copied from interface:BytesRetrieve a byte in this value. -
slice
Description copied from interface:BytesCreate 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
Bytes.copy()on the returned slice if that is not what you want. -
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
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.
-
toArray
public byte[] toArray()Description copied from interface:BytesExtract the bytes of this value into a byte array. -
toArray
Description copied from interface:BytesExtract the bytes of this value into a byte array. -
toArrayUnsafe
public byte[] toArrayUnsafe()Description copied from interface:BytesGet the bytes represented by this value as byte array.Contrarily to
Bytes.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.- Specified by:
toArrayUnsafein interfaceBytes- Returns:
- A byte array with the same content than this value, which may or may not be the direct backing of this value.
-
toString
Description copied from interface:BytesReturn the hexadecimal string representation of this value.- Specified by:
toStringin interfaceBytes- Overrides:
toStringin classAbstractBytes- Returns:
- The hexadecimal representation of this value, starting with "0x".
-
getInt
public int getInt(int i) Description copied from interface:BytesRetrieve the 4 bytes starting at the provided index in this value as an integer. -
getInt
Description copied from interface:BytesRetrieve the 4 bytes starting at the provided index in this value as an integer. -
toInt
public int toInt()Description copied from interface:BytesThe value corresponding to interpreting these bytes as an integer. -
toInt
Description copied from interface:BytesThe value corresponding to interpreting these bytes as an integer. -
isEmpty
public boolean isEmpty()Description copied from interface:BytesWhether this value contains no bytes. -
getLong
public long getLong(int i) Description copied from interface:BytesRetrieves the 8 bytes starting at the provided index in this value as a long. -
getLong
Description copied from interface:BytesRetrieves the 8 bytes starting at the provided index in this value as a long. -
toLong
public long toLong()Description copied from interface:BytesThe value corresponding to interpreting these bytes as a long. -
toLong
Description copied from interface:BytesThe value corresponding to interpreting these bytes as a long. -
toBigInteger
Description copied from interface:BytesThe BigInteger corresponding to interpreting these bytes as a two's-complement signed integer.- Specified by:
toBigIntegerin interfaceBytes- Returns:
- A
BigIntegercorresponding to interpreting these bytes as a two's-complement signed integer.
-
toBigInteger
Description copied from interface:BytesThe BigInteger corresponding to interpreting these bytes as a two's-complement signed integer.- Specified by:
toBigIntegerin interfaceBytes- Parameters:
order- The byte-order for decoding the integer.- Returns:
- A
BigIntegercorresponding to interpreting these bytes as a two's-complement signed integer.
-
toUnsignedBigInteger
Description copied from interface:BytesThe BigInteger corresponding to interpreting these bytes as an unsigned integer.- Specified by:
toUnsignedBigIntegerin interfaceBytes- Returns:
- A positive (or zero)
BigIntegercorresponding to interpreting these bytes as an unsigned integer.
-
toUnsignedBigInteger
Description copied from interface:BytesThe BigInteger corresponding to interpreting these bytes as an unsigned integer.- Specified by:
toUnsignedBigIntegerin interfaceBytes- Parameters:
order- The byte-order for decoding the integer.- Returns:
- A positive (or zero)
BigIntegercorresponding to interpreting these bytes as an unsigned integer.
-
isZero
public boolean isZero()Description copied from interface:BytesWhether this value has only zero bytes. -
hasLeadingZero
public boolean hasLeadingZero()Description copied from interface:BytesWhether the bytes start with a zero bit value.- Specified by:
hasLeadingZeroin interfaceBytes- Returns:
- true if the first bit equals zero
-
numberOfLeadingZeros
public int numberOfLeadingZeros()Description copied from interface:BytesProvides the number of zero bits preceding the highest-order ("leftmost") one-bit, orsize() * 8if all bits * are zero.- Specified by:
numberOfLeadingZerosin interfaceBytes- Returns:
- The number of zero bits preceding the highest-order ("leftmost") one-bit, or
size() * 8if all bits are zero.
-
hasLeadingZeroByte
public boolean hasLeadingZeroByte()Description copied from interface:BytesWhether the bytes start with a zero byte value.- Specified by:
hasLeadingZeroBytein interfaceBytes- Returns:
- true if the first byte equals zero
-
numberOfLeadingZeroBytes
public int numberOfLeadingZeroBytes()Description copied from interface:BytesProvides the number of leading zero bytes of the value- Specified by:
numberOfLeadingZeroBytesin interfaceBytes- Returns:
- The number of leading zero bytes of the value.
-
numberOfTrailingZeroBytes
public int numberOfTrailingZeroBytes()Description copied from interface:BytesProvides the number of trailing zero bytes of the value.- Specified by:
numberOfTrailingZeroBytesin interfaceBytes- Returns:
- The number of trailing zero bytes of the value.
-
bitLength
public int bitLength()Description copied from interface:BytesProvides the number of bits following and including the highest-order ("leftmost") one-bit, or zero if all bits are zero. -
and
Description copied from interface:BytesReturn 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.
-
and
Description copied from interface:BytesCalculate 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.
- Specified by:
andin interfaceBytes- 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
Description copied from interface:BytesReturn 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.
-
or
Description copied from interface:BytesCalculate 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.
- Specified by:
orin interfaceBytes- 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
Description copied from interface:BytesReturn 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.
-
xor
Description copied from interface:BytesCalculate 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.
- Specified by:
xorin interfaceBytes- 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.
-
shiftRight
Description copied from interface:BytesShift 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).
- Specified by:
shiftRightin interfaceBytes- 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
Description copied from interface:BytesShift 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.
- Specified by:
shiftLeftin interfaceBytes- 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
Description copied from interface:BytesCreate 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
Bytes.copy()on the returned slice if that is not what you want. -
copyTo
Description copied from interface:BytesCopy the bytes of this value to the provided mutable one, which must have the same size.- Specified by:
copyToin interfaceBytes- 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 useBytes.slice(int)and/orMutableBytes.mutableSlice(int, int)and apply the copy to the result.
-
copyTo
Description copied from interface:BytesCopy 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())). -
appendTo
Description copied from interface:BytesAppend the bytes of this value to theByteBuffer.- Specified by:
appendToin interfaceBytes- Parameters:
byteBuffer- TheByteBufferto which to append this value.
-
appendTo
public void appendTo(io.vertx.core.buffer.Buffer buffer) Description copied from interface:BytesAppend the bytes of this value to the provided Vert.xBuffer.Note that since a Vert.x
Bufferwill grow as necessary, this method never fails. -
appendHexTo
Description copied from interface:BytesAppend this value as a sequence of hexadecimal characters.- Specified by:
appendHexToin interfaceBytes- Type Parameters:
T- The appendable type.- Parameters:
appendable- The appendable- Returns:
- The appendable.
-
commonPrefixLength
Description copied from interface:BytesReturn the number of bytes in common between this set of bytes and another.- Specified by:
commonPrefixLengthin interfaceBytes- Parameters:
other- The bytes to compare to.- Returns:
- The number of common bytes.
-
commonPrefix
Description copied from interface:BytesReturn a slice over the common prefix between this set of bytes and another.- Specified by:
commonPrefixin interfaceBytes- Parameters:
other- The bytes to compare to.- Returns:
- A slice covering the common prefix.
-
trimLeadingZeros
Description copied from interface:BytesReturn a slice of representing the same value but without any leading zero bytes.- Specified by:
trimLeadingZerosin interfaceBytes- Returns:
valueif its left-most byte is non zero, or a slice that exclude any leading zero bytes.
-
update
Description copied from interface:BytesUpdate the provided message digest with the bytes of this value. -
reverse
Description copied from interface:BytesComputes the reverse array of bytes of the current bytes. -
toHexString
Description copied from interface:BytesProvides this value represented as hexadecimal, starting with "0x".- Specified by:
toHexStringin interfaceBytes- Returns:
- This value represented as hexadecimal, starting with "0x".
-
toUnprefixedHexString
Description copied from interface:BytesProvides this value represented as hexadecimal, with no prefix- Specified by:
toUnprefixedHexStringin interfaceBytes- Returns:
- This value represented as hexadecimal, with no prefix.
-
toEllipsisHexString
- Specified by:
toEllipsisHexStringin interfaceBytes
-
toShortHexString
Description copied from interface:BytesProvides this value represented as a minimal hexadecimal string (without any leading zero)- Specified by:
toShortHexStringin interfaceBytes- Returns:
- This value represented as a minimal hexadecimal string (without any leading zero).
-
toQuantityHexString
Description copied from interface:BytesProvides 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).- Specified by:
toQuantityHexStringin interfaceBytes- 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
Description copied from interface:BytesProvides this value represented as base 64- Specified by:
toBase64Stringin interfaceBytes- Returns:
- This value represented as base 64.
-
compareTo
- Specified by:
compareToin interfaceBytes- Specified by:
compareToin interfaceComparable<Bytes>
-
equals
Description copied from class:AbstractBytesCompare this value and the provided one for equality.Two
Bytesvalues are equal is they have contain the exact same bytes.- Overrides:
equalsin classAbstractBytes- Parameters:
o- The object to test for equality with.- Returns:
trueif this value andobjare equal.
-
hashCode
public int hashCode()- Overrides:
hashCodein classAbstractBytes
-