protected void capacity0(int requestedCapacity) { if (buf.isDerived()) { throw new IllegalStateException( "Derived buffers cannot be expanded."); } int newCapacity = MINIMUM_CAPACITY; while (newCapacity < requestedCapacity) { newCapacity <<= 1; } UnexpandableByteBuffer oldBuf = this.buf; boolean direct = isDirect(); UnexpandableByteBuffer newBuf; try { newBuf = allocate0(newCapacity, direct); } catch (OutOfMemoryError e) { if (direct) { newBuf = allocate0(newCapacity, false); } else { throw e; } } newBuf.buf().clear(); oldBuf.buf().clear(); newBuf.buf().put(oldBuf.buf()); this.buf = newBuf; oldBuf.release(); } }
public java.nio.ByteBuffer buf() { return buf.buf(); }