Methods Summary |
---|
public java.nio.ByteBuffer | acquire(int needed)
synchronized (this) {
for (;;) {
if (mAvailable != 0) {
mAvailable -= 1;
return grow(mBuffers[mAvailable], needed);
}
if (mAllocated < mBuffers.length) {
mAllocated += 1;
return ByteBuffer.allocate(chooseCapacity(mInitialBufferSize, needed));
}
try {
wait();
} catch (InterruptedException ex) {
}
}
}
|
private int | chooseCapacity(int capacity, int needed)
while (capacity < needed) {
capacity *= 2;
}
if (capacity > mMaxBufferSize) {
if (needed > mMaxBufferSize) {
throw new IllegalArgumentException("Requested size " + needed
+ " is larger than maximum buffer size " + mMaxBufferSize + ".");
}
capacity = mMaxBufferSize;
}
return capacity;
|
public java.nio.ByteBuffer | grow(java.nio.ByteBuffer buffer, int needed)
int capacity = buffer.capacity();
if (capacity < needed) {
final ByteBuffer oldBuffer = buffer;
capacity = chooseCapacity(capacity, needed);
buffer = ByteBuffer.allocate(capacity);
oldBuffer.flip();
buffer.put(oldBuffer);
}
return buffer;
|
public void | release(java.nio.ByteBuffer buffer)
synchronized (this) {
buffer.clear();
mBuffers[mAvailable++] = buffer;
notifyAll();
}
|