Package io.pravega.common.util
Interface ArrayView
-
- All Superinterfaces:
BufferView,StructuredReadableBuffer,StructuredWritableBuffer
- All Known Implementing Classes:
ByteArraySegment
public interface ArrayView extends BufferView, StructuredWritableBuffer, StructuredReadableBuffer
Defines a generic read-only view of an index-based, array-like structure.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.pravega.common.util.BufferView
BufferView.Collector<ExceptionT extends java.lang.Exception>, BufferView.Reader
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description byte[]array()Gets a reference to the backing array for this ArrayView.intarrayOffset()Gets a value indicating the offset in the backing array where this ArrayView starts at.java.nio.ByteBufferasByteBuffer()Returns a newByteBufferthat wraps the contents of thisArrayView.voidcopyTo(byte[] target, int targetOffset, int length)Copies a specified number of bytes from this ArrayView into the given target array.ArrayViewslice(int offset, int length)-
Methods inherited from interface io.pravega.common.util.BufferView
collect, copyTo, copyTo, getBufferViewReader, getCopy, getLength, getReader, getReader, iterateBuffers, release, retain, slice
-
Methods inherited from interface io.pravega.common.util.StructuredReadableBuffer
get, getInt, getLong, getShort, getUnsignedLong
-
Methods inherited from interface io.pravega.common.util.StructuredWritableBuffer
set, setInt, setLong, setShort, setUnsignedLong
-
-
-
-
Method Detail
-
array
byte[] array()
Gets a reference to the backing array for this ArrayView. This should be used in conjunction with arrayOffset() in order to determine where in the array this ArrayView starts at. NOTE: Care must be taken when using this array. Just like any other array in Java, it is modifiable and changes to it will be reflected in this ArrayView.- Returns:
- The backing array.
-
arrayOffset
int arrayOffset()
Gets a value indicating the offset in the backing array where this ArrayView starts at.- Returns:
- The offset in the backing array.
-
copyTo
void copyTo(byte[] target, int targetOffset, int length)Copies a specified number of bytes from this ArrayView into the given target array.- Parameters:
target- The target array.targetOffset- The offset within the target array to start copying data at.length- The number of bytes to copy.- Throws:
java.lang.ArrayIndexOutOfBoundsException- If targetOffset or length are invalid.
-
slice
ArrayView slice(int offset, int length)
Creates a newArrayViewthat represents a sub-range of thisArrayViewinstance. The new instance will share the same backing array as this one, so a change to one will be reflected in the other.- Specified by:
slicein interfaceBufferView- Parameters:
offset- The starting offset to begin the slice at.length- The sliced length.- Returns:
- A new
ArrayView.
-
-