@Test public void writableNioBuffers_indexesPreserved() { ByteBuf buf = alloc.buffer(1); int ridx = buf.readerIndex(); int widx = buf.writerIndex(); int cap = buf.capacity(); try (BufUnwrapper unwrapper = new BufUnwrapper()) { ByteBuffer[] internalBufs = unwrapper.writableNioBuffers(buf); Truth.assertThat(internalBufs).hasLength(1); internalBufs[0].put((byte) 'a'); assertEquals(ridx, buf.readerIndex()); assertEquals(widx, buf.writerIndex()); assertEquals(cap, buf.capacity()); } finally { buf.release(); } }
ByteBuffer[] writableNioBuffers(ByteBuf buf) { int readerIndex = buf.readerIndex(); int writerIndex = buf.writerIndex(); buf.readerIndex(writerIndex); buf.writerIndex(buf.capacity()); try { return nioBuffers(buf, singleWriteBuffer); } finally { buf.readerIndex(readerIndex); buf.writerIndex(writerIndex); } }
BufUnwrapper implements AutoCloseable { ByteBuffer[] writableNioBuffers(ByteBuf buf) { int readerIndex = buf.readerIndex(); int writerIndex = buf.writerIndex(); buf.readerIndex(writerIndex); buf.writerIndex(buf.capacity()); try { return nioBuffers(buf, singleWriteBuffer); } finally { buf.readerIndex(readerIndex); buf.writerIndex(writerIndex); } } }
BufUnwrapper implements AutoCloseable { ByteBuffer[] writableNioBuffers(ByteBuf buf) { int readerIndex = buf.readerIndex(); int writerIndex = buf.writerIndex(); buf.readerIndex(writerIndex); buf.writerIndex(buf.capacity()); try { return nioBuffers(buf, singleWriteBuffer); } finally { buf.readerIndex(readerIndex); buf.writerIndex(writerIndex); } }  }
BufUnwrapper implements AutoCloseable { ByteBuffer[] writableNioBuffers(ByteBuf buf) { int readerIndex = buf.readerIndex(); int writerIndex = buf.writerIndex(); buf.readerIndex(writerIndex); buf.writerIndex(buf.capacity()); try { return nioBuffers(buf, singleWriteBuffer); } finally { buf.readerIndex(readerIndex); buf.writerIndex(writerIndex); } }  @Override void close(); }
BufUnwrapper implements AutoCloseable { ByteBuffer[] writableNioBuffers(ByteBuf buf) { int readerIndex = buf.readerIndex(); int writerIndex = buf.writerIndex(); buf.readerIndex(writerIndex); buf.writerIndex(buf.capacity()); try { return nioBuffers(buf, singleWriteBuffer); } finally { buf.readerIndex(readerIndex); buf.writerIndex(writerIndex); } }  @Override void close();  }