1 modulehunt.net.secure.conscrypt.AllocatedBuffer;
2 3 importhunt.collection;
4 5 /**
6 * A buffer that was allocated by a {@link BufferAllocator}.
7 */8 abstractclassAllocatedBuffer {
9 /**
10 * Returns the {@link ByteBuffer} that backs this buffer.
11 */12 abstractByteBuffernioBuffer();
13 14 /**
15 * Increases the reference count by {@code 1}.
16 */17 abstractAllocatedBufferretain();
18 19 /**
20 * Decreases the reference count by {@code 1} and deallocates this object if the reference count
21 * reaches at {@code 0}.
22 *
23 * @return {@code true} if and only if the reference count became {@code 0} and this object has
24 * been deallocated
25 */26 abstractAllocatedBufferrelease();
27 28 /**
29 * Creates a new {@link AllocatedBuffer} that is backed by the given {@link ByteBuffer}.
30 */31 staticAllocatedBufferwrap(ByteBufferbuffer) {
32 // checkNotNull(buffer, "buffer");33 34 returnnewclassAllocatedBuffer {
35 36 override37 ByteBuffernioBuffer() {
38 returnbuffer;
39 }
40 41 override42 AllocatedBufferretain() {
43 // Do nothing.44 returnthis;
45 }
46 47 override48 AllocatedBufferrelease() {
49 // Do nothing.50 returnthis;
51 }
52 };
53 }
54 }
55 56 57 58 /**
59 * An object responsible for allocation of buffers. This is an extension point to enable buffer
60 * pooling within an application.
61 */62 abstractclassBufferAllocator {
63 private__gsharedstaticBufferAllocatorUNPOOLED;
64 65 sharedstaticthis()
66 {
67 UNPOOLED = newclassBufferAllocator {
68 override69 AllocatedBufferallocateDirectBuffer(intcapacity) {
70 returnAllocatedBuffer.wrap(newHeapByteBuffer(capacity,capacity));
71 // ByteBuffer.allocateDirect(capacity)72 }
73 };
74 }
75 76 /**
77 * Returns an unpooled buffer allocator, which will create a new buffer for each request.
78 */79 staticBufferAllocatorunpooled() {
80 returnUNPOOLED;
81 }
82 83 /**
84 * Allocates a direct (i.e. non-heap) buffer with the given capacity.
85 */86 abstractAllocatedBufferallocateDirectBuffer(intcapacity);
87 }