Package io.deephaven.util
Class BufferUtil
java.lang.Object
io.deephaven.util.BufferUtil
Utility methods for working with ByteBuffers.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic ByteBuffer
ensureSpace
(ByteBuffer dataBuffer, int requiredSize) Return a buffer with at least requiredSize remaining capacity.static ByteBuffer
reallocateBuffer
(@NotNull ByteBuffer buffer, int minimumSize) Allocate a new ByteBuffer larger than the supplied buffer.static ByteBuffer
writeUtf8
(ByteBuffer dataBuffer, String value) Encode the given string as UTF_8 and write the size and data to the given buffer.
-
Constructor Details
-
BufferUtil
public BufferUtil()
-
-
Method Details
-
reallocateBuffer
Allocate a new ByteBuffer larger than the supplied buffer. This is generally used when dynamically resizing an output buffer.
The resulting buffer's size will be a power-of-two at least double the supplied buffer's size and at least the specified minimum size, unless constrained by
Integer.MAX_VALUE
.The resulting buffer will be direct if and only if the supplied buffer was direct.
The contents of the supplied buffer are copied into the result buffer as in
ByteBuffer.put(ByteBuffer)
.
See also io.deephaven.tablelogger.AbstractBinaryStoreWriter#ensureSpace- Parameters:
buffer
- The buffer to grow (and copy from)minimumSize
- The minimum size for the result buffer- Returns:
- The new buffer, including contents of buffer
-
ensureSpace
Return a buffer with at least requiredSize remaining capacity. The provided buffer will be copied to the new buffer, and might be the buffer returned. The new buffer's limit will be unchanged if the buffer is not reallocated, and equal to the new capacity if it is reallocated. The new buffer will be allocated with allocateDirect() if the original buffer is direct, else with allocate().- Parameters:
dataBuffer
- a byte buffer in write moderequiredSize
- additional capacity needed- Returns:
- a byte buffer in write mode with at least requiredSize remaining capacity
-
writeUtf8
Encode the given string as UTF_8 and write the size and data to the given buffer. The buffer might be reallocated usingensureSpace(java.nio.ByteBuffer, int)
if necessary.- Parameters:
dataBuffer
- Write to this ByteBuffer.value
- Encode this string.- Returns:
- The modified input ByteBuffer.
-