@Test public void testInout() throws Exception { ByteArrayOutputStreamPayload payload = new ByteArrayOutputStreamPayload(); String randomStr = randomString(); ByteBuf byteBuf = directByteBuf(randomStr.length()); byteBuf.writeBytes(randomStr.getBytes()); payload.startInput(); payload.in(byteBuf); payload.endInput(); final ByteBuf result = directByteBuf(randomStr.length()); payload.startOutput(); long wroteLength = payload.out(new WritableByteChannel() { @Override public boolean isOpen() { return false; } @Override public void close() throws IOException { } @Override public int write(ByteBuffer src) throws IOException { int readable = result.readableBytes(); result.writeBytes(src); return result.readableBytes() - readable; } }); payload.endOutput(); Assert.assertEquals(randomStr.length(), wroteLength); byte []resultArray = new byte[(int) wroteLength]; result.readBytes(resultArray); Assert.assertEquals(randomStr, new String(resultArray)); }
public byte[] getBytes(){ int currentPos = pos.get(); byte []dst = new byte[currentPos]; System.arraycopy(data, 0, dst, 0, currentPos); return dst; }
ByteArrayOutputStreamPayload extends AbstractInOutPayload { public byte[] getBytes(){ int currentPos = pos.get(); byte []dst = new byte[currentPos]; System.arraycopy(data, 0, dst, 0, currentPos); return dst; } }
ByteArrayOutputStreamPayload extends AbstractInOutPayload { public byte[] getBytes(){ int currentPos = pos.get(); byte []dst = new byte[currentPos]; System.arraycopy(data, 0, dst, 0, currentPos); return dst; } ByteArrayOutputStreamPayload();  ByteArrayOutputStreamPayload(int INIT_SIZE);  ByteArrayOutputStreamPayload(String message); }
ByteArrayOutputStreamPayload extends AbstractInOutPayload { public byte[] getBytes(){ int currentPos = pos.get(); byte []dst = new byte[currentPos]; System.arraycopy(data, 0, dst, 0, currentPos); return dst; } ByteArrayOutputStreamPayload();  ByteArrayOutputStreamPayload(int INIT_SIZE);  ByteArrayOutputStreamPayload(String message); @Override void doStartInput(); @Override int doIn(ByteBuf byteBuf); @Override long doOut(WritableByteChannel writableByteChannel); byte[] getBytes(); @Override String toString(); }
ByteArrayOutputStreamPayload extends AbstractInOutPayload { public byte[] getBytes(){ int currentPos = pos.get(); byte []dst = new byte[currentPos]; System.arraycopy(data, 0, dst, 0, currentPos); return dst; } ByteArrayOutputStreamPayload();  ByteArrayOutputStreamPayload(int INIT_SIZE);  ByteArrayOutputStreamPayload(String message); @Override void doStartInput(); @Override int doIn(ByteBuf byteBuf); @Override long doOut(WritableByteChannel writableByteChannel); byte[] getBytes(); @Override String toString();  }