private void free(ByteBuffer oldBuf) { if ((oldBuf == null) || ((maxCachedBufferSize != 0) && (oldBuf.capacity() > maxCachedBufferSize)) || oldBuf.isReadOnly() || isDerived() || (Thread.currentThread() != ownerThread)) { return; } // Add to the cache. Queue<CachedBuffer> pool; if (oldBuf.isDirect()) { pool = directBuffers.get().get(oldBuf.capacity()); } else { pool = heapBuffers.get().get(oldBuf.capacity()); } if (pool == null) { return; } // Restrict the size of the pool to prevent OOM. if ((maxPoolSize == 0) || (pool.size() < maxPoolSize)) { pool.offer(new CachedBuffer(oldBuf)); } } }
@Override public byte[] array() { return buf().array(); }
private void free(ByteBuffer oldBuf) { if (oldBuf == null || oldBuf.capacity() > maxCachedBufferSize || oldBuf.isReadOnly() || isDerived() || Thread.currentThread() != ownerThread) { return; } // Add to the cache. Queue<CachedBuffer> pool; if (oldBuf.isDirect()) { pool = directBuffers.get().get(oldBuf.capacity()); } else { pool = heapBuffers.get().get(oldBuf.capacity()); } if (pool == null) { return; } // Restrict the size of the pool to prevent OOM. if (maxPoolSize == 0 || pool.size() < maxPoolSize) { pool.offer(new CachedBuffer(oldBuf)); } } }
private void free(ByteBuffer oldBuf) { if ((oldBuf == null) || ((maxCachedBufferSize != 0) && (oldBuf.capacity() > maxCachedBufferSize)) || oldBuf.isReadOnly() || isDerived() || (Thread.currentThread() != ownerThread)) { return; } // Add to the cache. Queue<CachedBuffer> pool; if (oldBuf.isDirect()) { pool = directBuffers.get().get(oldBuf.capacity()); } else { pool = heapBuffers.get().get(oldBuf.capacity()); } if (pool == null) { return; } // Restrict the size of the pool to prevent OOM. if ((maxPoolSize == 0) || (pool.size() < maxPoolSize)) { pool.offer(new CachedBuffer(oldBuf)); } } }
@Override public boolean hasArray() { return buf().hasArray(); }
public IoBuffer wrap(ByteBuffer nioBuffer) { return new CachedBuffer(nioBuffer); }
@Override public int arrayOffset() { return buf().arrayOffset(); }
@Override protected IoBuffer asReadOnlyBuffer0() { return new CachedBuffer(this, buf().asReadOnlyBuffer()); }
@Override public boolean hasArray() { return buf().hasArray(); }
@Override public byte[] array() { return buf().array(); }
@Override protected IoBuffer slice0() { return new CachedBuffer(this, buf().slice()); }
@Override protected IoBuffer slice0() { return new CachedBuffer(this, buf().slice()); }
@Override protected IoBuffer asReadOnlyBuffer0() { return new CachedBuffer(this, buf().asReadOnlyBuffer()); }
@Override public void free() { free(buf); buf = null; }
@Override public int arrayOffset() { return buf().arrayOffset(); }
/** * {@inheritDoc} */ @Override public IoBuffer wrap(ByteBuffer nioBuffer) { return new CachedBuffer(nioBuffer); }
@Override protected IoBuffer duplicate0() { return new CachedBuffer(this, buf().duplicate()); }
@Override public int arrayOffset() { return buf().arrayOffset(); }
@Override protected IoBuffer duplicate0() { return new CachedBuffer(this, buf().duplicate()); }
@Override protected void buf(ByteBuffer buf) { ByteBuffer oldBuf = this.buf; this.buf = buf; free(oldBuf); }