Class DelegatingMutableBytes
- All Implemented Interfaces:
Comparable<Bytes>,Bytes,MutableBytes
This class may be used to create more types that represent bytes, but need a different name for business logic.
-
Field Summary
Fields inherited from interface org.apache.tuweni.bytes.MutableBytes
EMPTY -
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.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.voidclear()Set all bytes in this value to 0.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.copy()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.Decrements the value of the bytes by 1, treating the value as big endian.booleanvoidfill(byte b) Fill all the bytes of this value with the specified byte.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.longgetLong(int i) Retrieves 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.Increments the value of the bytes by 1, treating the value as big endian.booleanisZero()Whether this value has only zero bytes.Return a new mutable value initialized with the content of this value.mutableSlice(int i, int length) Create a mutable slice of the bytes of this value.<T extends MutableBytes>
Tnot(T result) Calculate a bit-wise NOT of these bytes.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.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.voidset(int i, byte b) Set a byte in this value.voidSet a byte in this value.voidsetInt(int i, int value) Set the 4 bytes starting at the specified index to the specified integer value.voidsetLong(int i, long value) Set the 8 bytes starting at the specified index to the specified long value.<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 index) 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[]Get the bytes represented by this value as byte array.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.longtoLong()The value corresponding to interpreting these bytes as a long.Provides this value represented as a minimal hexadecimal string (without any leading zero)toString()Return the hexadecimal string representation of this value.The BigInteger corresponding to interpreting these bytes as an unsigned integer.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 java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.tuweni.bytes.Bytes
appendHexTo, compareTo, getInt, getLong, isEmpty, not, numberOfTrailingZeroBytes, reverse, shiftLeft, shiftRight, toArray, toBase64String, toBigInteger, toEllipsisHexString, toFastHex, toInt, toLong, toQuantityHexString, toUnprefixedHexString, toUnsignedBigInteger, trimLeadingZeros, trimTrailingZeros
-
Constructor Details
-
DelegatingMutableBytes
-
-
Method Details
-
set
public void set(int i, byte b) Description copied from interface:MutableBytesSet a byte in this value.- Specified by:
setin interfaceMutableBytes- Parameters:
i- The index of the byte to set.b- The value to set that byte to.
-
set
Description copied from interface:MutableBytesSet a byte in this value.- Specified by:
setin interfaceMutableBytes- Parameters:
i- The offset of the bytes to set.b- The value to set bytes to.
-
setInt
public void setInt(int i, int value) Description copied from interface:MutableBytesSet the 4 bytes starting at the specified index to the specified integer value.- Specified by:
setIntin interfaceMutableBytes- Parameters:
i- The index, which must less than or equal tosize() - 4.value- The integer value.
-
setLong
public void setLong(int i, long value) Description copied from interface:MutableBytesSet the 8 bytes starting at the specified index to the specified long value.- Specified by:
setLongin interfaceMutableBytes- Parameters:
i- The index, which must less than or equal tosize() - 8.value- The long value.
-
increment
Description copied from interface:MutableBytesIncrements the value of the bytes by 1, treating the value as big endian.If incrementing overflows the value then all bits flip, i.e. incrementing 0xFFFF will return 0x0000.
- Specified by:
incrementin interfaceMutableBytes- Returns:
- this value
-
decrement
Description copied from interface:MutableBytesDecrements the value of the bytes by 1, treating the value as big endian.If decrementing underflows the value then all bits flip, i.e. decrementing 0x0000 will return 0xFFFF.
- Specified by:
decrementin interfaceMutableBytes- Returns:
- this value
-
mutableSlice
Description copied from interface:MutableBytesCreate a mutable slice of the bytes of this value.Note: the resulting slice is only a view over the original value. Holding a reference to the returned slice may hold more memory than the slide represents. Use
Bytes.copy()on the returned slice to avoid this.- Specified by:
mutableSlicein interfaceMutableBytes- Parameters:
i- The start index for the slice.length- The length of the resulting value.- Returns:
- A new mutable view over the bytes of this value from index
i(included) to indexi + length(excluded).
-
fill
public void fill(byte b) Description copied from interface:MutableBytesFill all the bytes of this value with the specified byte.- Specified by:
fillin interfaceMutableBytes- Parameters:
b- The byte to use to fill the value.
-
clear
public void clear()Description copied from interface:MutableBytesSet all bytes in this value to 0.- Specified by:
clearin interfaceMutableBytes
-
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. -
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. -
toInt
public int toInt()Description copied from interface:BytesThe value corresponding to interpreting these bytes as an integer. -
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. -
toLong
public 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.
-
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.
-
isZero
public boolean isZero()Description copied from interface:BytesWhether this value has only zero bytes. -
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.
-
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.
-
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
-
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
-
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.
-
not
Description copied from interface:BytesCalculate 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.
- Specified by:
notin interfaceBytes- Type Parameters:
T- TheMutableBytesvalue type.- Parameters:
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. -
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.
-
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. -
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.
-
update
Description copied from interface:BytesUpdate the provided message digest with the bytes of this value. -
toArray
public byte[] 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. -
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".
-
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).
-
equals
-
hashCode
public int hashCode()
-