-
public interface InternalBufferUtils
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
InternalBufferUtils.UncheckedLoadByte
This interface provides the fastest possible offsetted byte-access to a buffer.
-
Field Summary
Fields Modifier and Type Field Description static MethodHandle
BB_PUT_OFFSETS
static MethodHandle
BB_SLICE_OFFSETS
static Cleaner
CLEANER
static int
MAX_BUFFER_SIZE
The maximum buffer size we support is the maximum array length generally supported by JVMs, because on-heap buffers will be backed by byte-arrays.static LongAdder
MEM_USAGE_NATIVE
static Drop<Buffer>
NO_OP_DROP
static InternalBufferUtils.UncheckedLoadByte
UNCHECKED_LOAD_BYTE_BUFFER
-
Method Summary
Static Methods Modifier and Type Method Description static <T> T
acquire(ResourceSupport<?,?> obj)
static IllegalStateException
allocatorClosedException()
static void
assertValidBufferSize(long size)
Check the givensize
argument is a valid buffer size, or throw anIllegalArgumentException
.static <E extends Throwable>
EattachTrace(ResourceSupport<?,?> obj, E throwable)
static void
bbput(ByteBuffer dest, int destPos, ByteBuffer src, int srcPos, int length)
The ByteBuffer put-buffer-with-offset-and-length method is not available in Java 11.static ByteBuffer
bbslice(ByteBuffer buffer, int fromOffset, int length)
The ByteBuffer slice-with-offset-and-length method is only available from Java 13 and onwards, but we need to support Java 11.static BufferClosedException
bufferIsClosed(Buffer buffer)
static BufferReadOnlyException
bufferIsReadOnly(Buffer buffer)
static int
bytesBefore(Buffer haystack, InternalBufferUtils.UncheckedLoadByte hl, Buffer needle, InternalBufferUtils.UncheckedLoadByte nl)
static void
checkImplicitCapacity(int implicitCapacity, int currentCapacity)
static void
checkLength(int length)
static <T,R>
Drop<R>convert(Drop<T> drop)
static CharSequence
copyToCharSequence(Buffer source, int srcIdx, int length, Charset charset)
static void
copyToViaReverseLoop(Buffer src, int srcPos, Buffer dest, int destPos, int length)
static int
countBorrows(ResourceSupport<?,?> obj)
static boolean
equals(Buffer a, int aStartIndex, Buffer b, int bStartIndex, int length)
static boolean
equals(Buffer bufferA, Buffer bufferB)
static VarHandle
findVarHandle(MethodHandles.Lookup lookup, Class<?> recv, String name, Class<?> type)
static MethodHandle
getByteBufferPutOffsetsMethodHandle()
static MethodHandle
getByteBufferSliceOffsetsMethodHandle()
static int
hashCode(Buffer buffer)
static boolean
isOwned(ResourceSupport<?,?> obj)
static long
nativeAddressOfDirectByteBuffer(ByteBuffer byteBuffer)
static long
nativeAddressWithOffset(long address, int offset)
Compute an offset into a native address.static CharSequence
readCharSequence(Buffer source, int length, Charset charset)
static void
setMemory(ByteBuffer buffer, int length, byte value)
static Function<Drop<Buffer>,Drop<Buffer>>
standardDrop(MemoryManager manager)
static String
toString(Buffer source, Charset charset)
static ByteBuffer
tryGetWritableBufferFromReadableComponent(BufferComponent component)
static void
unsafeSetDrop(ResourceSupport<?,?> obj, Drop<?> replacement)
static void
writeCharSequence(CharSequence source, Buffer destination, Charset charset)
-
-
-
Field Detail
-
MEM_USAGE_NATIVE
static final LongAdder MEM_USAGE_NATIVE
-
CLEANER
static final Cleaner CLEANER
-
BB_SLICE_OFFSETS
static final MethodHandle BB_SLICE_OFFSETS
-
BB_PUT_OFFSETS
static final MethodHandle BB_PUT_OFFSETS
-
MAX_BUFFER_SIZE
static final int MAX_BUFFER_SIZE
The maximum buffer size we support is the maximum array length generally supported by JVMs, because on-heap buffers will be backed by byte-arrays.- See Also:
- Constant Field Values
-
UNCHECKED_LOAD_BYTE_BUFFER
static final InternalBufferUtils.UncheckedLoadByte UNCHECKED_LOAD_BYTE_BUFFER
-
-
Method Detail
-
getByteBufferSliceOffsetsMethodHandle
static MethodHandle getByteBufferSliceOffsetsMethodHandle()
-
getByteBufferPutOffsetsMethodHandle
static MethodHandle getByteBufferPutOffsetsMethodHandle()
-
findVarHandle
static VarHandle findVarHandle(MethodHandles.Lookup lookup, Class<?> recv, String name, Class<?> type)
-
assertValidBufferSize
static void assertValidBufferSize(long size)
Check the givensize
argument is a valid buffer size, or throw anIllegalArgumentException
.- Parameters:
size
- The size to check.- Throws:
IllegalArgumentException
- if the size is not positive, or if the size is too big (over ~2 GB) for a buffer to accommodate.
-
checkImplicitCapacity
static void checkImplicitCapacity(int implicitCapacity, int currentCapacity)
-
checkLength
static void checkLength(int length)
-
copyToViaReverseLoop
static void copyToViaReverseLoop(Buffer src, int srcPos, Buffer dest, int destPos, int length)
-
tryGetWritableBufferFromReadableComponent
static ByteBuffer tryGetWritableBufferFromReadableComponent(BufferComponent component)
-
bbslice
static ByteBuffer bbslice(ByteBuffer buffer, int fromOffset, int length)
The ByteBuffer slice-with-offset-and-length method is only available from Java 13 and onwards, but we need to support Java 11.
-
bbput
static void bbput(ByteBuffer dest, int destPos, ByteBuffer src, int srcPos, int length)
The ByteBuffer put-buffer-with-offset-and-length method is not available in Java 11.
-
setMemory
static void setMemory(ByteBuffer buffer, int length, byte value)
-
bufferIsClosed
static BufferClosedException bufferIsClosed(Buffer buffer)
-
bufferIsReadOnly
static BufferReadOnlyException bufferIsReadOnly(Buffer buffer)
-
allocatorClosedException
static IllegalStateException allocatorClosedException()
-
acquire
static <T> T acquire(ResourceSupport<?,?> obj)
-
isOwned
static boolean isOwned(ResourceSupport<?,?> obj)
-
countBorrows
static int countBorrows(ResourceSupport<?,?> obj)
-
attachTrace
static <E extends Throwable> E attachTrace(ResourceSupport<?,?> obj, E throwable)
-
unsafeSetDrop
static void unsafeSetDrop(ResourceSupport<?,?> obj, Drop<?> replacement)
-
readCharSequence
static CharSequence readCharSequence(Buffer source, int length, Charset charset)
-
copyToCharSequence
static CharSequence copyToCharSequence(Buffer source, int srcIdx, int length, Charset charset)
-
writeCharSequence
static void writeCharSequence(CharSequence source, Buffer destination, Charset charset)
-
hashCode
static int hashCode(Buffer buffer)
-
nativeAddressWithOffset
static long nativeAddressWithOffset(long address, int offset)
Compute an offset into a native address. Zero is used as a marker for when a native address is not available, and an offset into a zero address will remain zero.- Parameters:
address
- The native address, or zero if no native address is available.offset
- The offset into the native address we wish to compute.- Returns:
- An offsetted native address, or zero if no native address was available.
-
nativeAddressOfDirectByteBuffer
static long nativeAddressOfDirectByteBuffer(ByteBuffer byteBuffer)
-
bytesBefore
static int bytesBefore(Buffer haystack, InternalBufferUtils.UncheckedLoadByte hl, Buffer needle, InternalBufferUtils.UncheckedLoadByte nl)
-
-