NioSslEngine implements NioFilter { @Override public ByteBuffer ensureWrappedCapacity(int amount, ByteBuffer wrappedBuffer, BufferType bufferType) { ByteBuffer buffer = wrappedBuffer; int requiredSize = engine.getSession().getPacketBufferSize(); if (buffer == null) { buffer = bufferPool.acquireDirectBuffer(bufferType, requiredSize); } else if (buffer.capacity() < requiredSize) { buffer = bufferPool.expandWriteBufferIfNeeded(bufferType, buffer, requiredSize); } return buffer; } NioSslEngine(SSLEngine engine, BufferPool bufferPool); boolean handshake(SocketChannel socketChannel, int timeout,
      ByteBuffer peerNetData); @Override synchronized ByteBuffer wrap(ByteBuffer appData); @Override synchronized ByteBuffer unwrap(ByteBuffer wrappedBuffer); @Override ByteBuffer ensureWrappedCapacity(int amount, ByteBuffer wrappedBuffer,
      BufferType bufferType); @Override ByteBuffer readAtLeast(SocketChannel channel, int bytes,
      ByteBuffer wrappedBuffer); @Override ByteBuffer getUnwrappedBuffer(ByteBuffer wrappedBuffer); ByteBuffer ensureUnwrappedCapacity(int amount); @Override void doneReadingDirectAck(ByteBuffer unwrappedBuffer); @Override synchronized void close(SocketChannel socketChannel);  }
@Test public void ensureWrappedCapacityOfSmallMessage() { ByteBuffer buffer = ByteBuffer.allocate(netBufferSize); assertThat( nioSslEngine.ensureWrappedCapacity(10, buffer, BufferPool.BufferType.UNTRACKED)) .isEqualTo(buffer); }
@Test public void ensureWrappedCapacityWithNoBuffer() { assertThat( nioSslEngine.ensureWrappedCapacity(10, null, BufferPool.BufferType.UNTRACKED) .capacity()) .isEqualTo(netBufferSize); }