Class MutableByteBufferWrappingBytes
- All Implemented Interfaces:
Comparable<Bytes>,Bytes,MutableBytes
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ByteBufferprotected final intprotected final intFields inherited from interface org.apache.tuweni.bytes.MutableBytes
EMPTY -
Method Summary
Modifier and TypeMethodDescriptionvoidappendTo(ByteBuffer byteBuffer) Append the bytes of this value to theByteBuffer.copy()Return a value equivalent to this one but guaranteed to 1) be deeply immutable (i.e.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()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.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.intsize()Provides the number of bytes this value represents.slice(int i, 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.Methods inherited from class org.apache.tuweni.bytes.AbstractBytes
computeHashcode, equals, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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, mutableCopy, not, not, numberOfLeadingZeroBytes, numberOfLeadingZeros, numberOfTrailingZeroBytes, or, or, reverse, shiftLeft, shiftLeft, shiftRight, shiftRight, size, 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, xorMethods inherited from interface org.apache.tuweni.bytes.MutableBytes
clear, decrement, fill, increment
-
Field Details
-
byteBuffer
-
offset
protected final int offset -
length
protected final int length
-
-
Method Details
-
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.
-
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.
-
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).
-
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. -
hashCode
public int hashCode()- Overrides:
hashCodein classAbstractBytes
-
size
public int size()Description copied from interface:BytesProvides the number of bytes this value represents.- Returns:
- The number of bytes this value represents.
-
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.- 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.
-
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.- 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.
-
get
public byte get(int i) Description copied from interface:BytesRetrieve 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.
-
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.- 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).
-
mutableCopy
Description copied from interface:BytesReturn 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.
-
appendTo
Description copied from interface:BytesAppend the bytes of this value to theByteBuffer.- Parameters:
byteBuffer- TheByteBufferto which to append this value.
-
toArray
public byte[] toArray()Description copied from interface:BytesExtract the bytes of this value into a byte array.- Returns:
- A byte array with the same content than this value.
-
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.- Returns:
- A byte array with the same content than this value, which may or may not be the direct backing of this value.
-