BufferAllocator is for allocating off-heap
Buffers that may contain sensitive information, which should be erased from memory (overwritten) when the
buffer is closed.
The features and behaviours of this allocator are otherwise exactly the same as
BufferAllocator#offHeapUnpooled().
Of particular note, the byte arrays passed to BufferAllocator#copyOf(byte[])
and BufferAllocator#constBufferSupplier(byte[]), and the buffer passed to
BufferAllocator#copyOf(ByteBuffer) are not cleared by this allocator.
These copies of the sensitive data must be cleared separately!
Ideally these methods should not be used for sensitive data in the first place, and the sensitive data should
instead be directly written to, or created in, a sensitive buffer.
This allocator is stateless, and the close() method has no effect.
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private final AllocatorControl | |
| private final Function | |
| private static final BufferAllocator | |
| private final MemoryManager |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public Buffer | allocate(int
The size of size)Buffer to allocate.Implements io. Buffer of the given size in bytes.
|
| public void | close()
Implements io. |
| public Supplier | constBufferSupplier(byte[]
The byte contents of the buffers produced by the returned supplier. bytes)Implements io. |
| private Drop | |
| public AllocationType | getAllocationType()
Implements io. AllocationType from this allocator.
|
| private MemoryManager | |
| public boolean | isPooling()
Implements io. |
| public static BufferAllocator | Returns: The allocator.Get the sensitive off-heap buffer allocator instance. |
| control | back to summary |
|---|---|
| private final AllocatorControl control | |
| decorator | back to summary |
|---|---|
| private final Function<Drop<Buffer>, Drop<Buffer>> decorator | |
| INSTANCE | back to summary |
|---|---|
| private static final BufferAllocator INSTANCE | |
| manager | back to summary |
|---|---|
| private final MemoryManager manager | |
| SensitiveBufferAllocator | back to summary |
|---|---|
| private SensitiveBufferAllocator(MemoryManager manager) | |
| allocate | back to summary |
|---|---|
| public Buffer allocate(int size) Implements io. Doc from io. Allocate a The buffer will use big endian byte order. Note unlike the JDK | |
| close | back to summary |
|---|---|
| public void close() Implements io. Doc from io. Close this allocator, freeing all of its internal resources. Existing (currently in-use) allocated buffers will not be impacted by calling this method. If this is a pooling or caching allocator, then existing buffers will be immediately freed when they are closed, instead of being pooled or cached.
The allocator can no longer be used to allocate more buffers after calling this method.
Attempting to allocate from a closed allocator will cause
| |
| constBufferSupplier | back to summary |
|---|---|
| public Supplier Implements io. Doc from io. Create a supplier of "constant" Buffers from this allocator, that all have the given byte contents. The buffer has the same capacity as the byte array length, and its write offset is placed at the end, and its read offset is at the beginning, such that the entire buffer contents are readable. The buffers produced by the supplier will each have their own independent life-cycle, and closing them will make them inaccessible, just like normally allocated buffers. The buffers produced are "constants", in the sense that they are read-only. It can generally be expected, but is not guaranteed, that the returned supplier is more resource efficient than allocating and copying memory with other available APIs. In such optimised implementations, the underlying memory baking the buffers will be shared among all the buffers produced by the supplier.
The primary use case for this API, is when you need to repeatedly produce buffers with the same contents, and
you perhaps wish to keep a | |
| decorate | back to summary |
|---|---|
| private Drop | |
| getAllocationType | back to summary |
|---|---|
| public AllocationType getAllocationType() Implements io. Doc from io. Get the
| |
| getManager | back to summary |
|---|---|
| private MemoryManager getManager() | |
| isPooling | back to summary |
|---|---|
| public boolean isPooling() Implements io. Doc from io. Determine if this allocator is pooling and reusing its allocated memory.
| |
| sensitiveOffHeapAllocator | back to summary |
|---|---|
| public static BufferAllocator sensitiveOffHeapAllocator() Get the sensitive off-heap buffer allocator instance.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final Drop | |
| private final MemoryManager |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | attach(Buffer
The new obj)Resource instance with the new owner.Implements io. |
| public void | drop(Buffer
The obj)Resource instance being dropped.Implements io. Resource instance.
|
| public Drop | |
| public String |
| base | back to summary |
|---|---|
| private final Drop<Buffer> base | |
| manager | back to summary |
|---|---|
| private final MemoryManager manager | |
| ZeroingDrop | back to summary |
|---|---|
| pack-priv ZeroingDrop(MemoryManager manager, Drop<Buffer> base) | |
| attach | back to summary |
|---|---|
| public void attach(Buffer obj) Implements io. Doc from io. Called when the resource changes owner. | |
| drop | back to summary |
|---|---|
| public void drop(Buffer obj) Implements io. Doc from io. Dispose of the resources in the given | |
| fork | back to summary |
|---|---|
| public Drop Implements io. Doc from io. Branch the responsibility of dropping a resource. This drop instance will remain associated with its current resource, while the returned drop instance must be attached to its new resource. | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |