/** * Mark this {@link Channel} as finished and release all pending message in the inbound and outbound buffer. * Any further try to write data to it will fail. * * @return bufferReadable returns {@code true} if any of the used buffers has something left to read */ public boolean finishAndReleaseAll() { return finish(true); }
/** * Mark this {@link Channel} as finished. Any further try to write data to it will fail. * * @return bufferReadable returns {@code true} if any of the used buffers has something left to read */ public boolean finish() { return finish(false); }
/** * Mark this {@link Channel} as finished and release all pending message in the inbound and outbound buffer. * Any further try to write data to it will fail. * * @return bufferReadable returns {@code true} if any of the used buffers has something left to read */ public boolean finishAndReleaseAll() { return finish(true); }
/** * Mark this {@link Channel} as finished. Any further try to write data to it will fail. * * @return bufferReadable returns {@code true} if any of the used buffers has something left to read */ public boolean finish() { return finish(false); }
/** * Mark this {@link Channel} as finished. Any further try to write data to it will fail. * * @return bufferReadable returns {@code true} if any of the used buffers has something left to read */ public boolean finish() { return finish(false); }
/** * Mark this {@link Channel} as finished and release all pending message in the inbound and outbound buffer. * Any further try to write data to it will fail. * * @return bufferReadable returns {@code true} if any of the used buffers has something left to read */ public boolean finishAndReleaseAll() { return finish(true); }
private void finishEncode(List<Object> out) { if (encoder.finish()) { fetchEncoderOutput(out); } encoder = null; }
private void finishDecode(List<Object> out) { if (decoder.finish()) { fetchDecoderOutput(out); } decoder = null; }
private void cleanup() { if (encoder != null) { // Clean-up the previous encoder if not cleaned up correctly. if (encoder.finish()) { for (;;) { ByteBuf buf = encoder.readOutbound(); if (buf == null) { break; } // Release the buffer buf.release(); } } encoder = null; } } }
private void cleanup() { if (decoder != null) { // Clean-up the previous encoder if not cleaned up correctly. if (decoder.finish()) { for (;;) { ByteBuf buf = decoder.readOutbound(); if (buf == null) { break; } // Release the buffer buf.release(); } } decoder = null; } } }
@Override public HttpData finish() { if (decoder.finish()) { return HttpData.of(fetchDecoderOutput()); } else { return HttpData.EMPTY_DATA; } }
/** * Release remaining content from {@link EmbeddedChannel} and remove the compressor from the {@link Http2Stream}. * * @param stream The stream for which {@code compressor} is the compressor for * @param compressor The compressor for {@code stream} */ void cleanup(Http2Stream stream, EmbeddedChannel compressor) { if (compressor.finish()) { for (;;) { final ByteBuf buf = compressor.readOutbound(); if (buf == null) { break; } buf.release(); } } stream.removeProperty(propertyKey); }
@Test public void shouldDecodeMaxSizeChunk() { byte[] message = new byte[0xFFFF]; ByteBuf input = buffer(); input.writeShort( message.length ); input.writeBytes( message ); assertTrue( channel.writeInbound( input ) ); assertTrue( channel.finish() ); assertEquals( 1, channel.inboundMessages().size() ); assertByteBufEquals( wrappedBuffer( message ), channel.readInbound() ); } }
@Test public void shouldDecodeFullChunk() { // whole chunk with header and body arrives at once ByteBuf input = buffer(); input.writeShort( 7 ); input.writeByte( 1 ); input.writeByte( 11 ); input.writeByte( 2 ); input.writeByte( 22 ); input.writeByte( 3 ); input.writeByte( 33 ); input.writeByte( 4 ); // after buffer is written there should be something to read on the other side assertTrue( channel.writeInbound( input ) ); assertTrue( channel.finish() ); // there should only be a single chunk available for reading assertEquals( 1, channel.inboundMessages().size() ); // it should have no size header and expected body assertByteBufEquals( input.slice( 2, 7 ), channel.readInbound() ); }
@Test public void shouldDecodeMessageWithSingleChunk() { assertFalse( channel.writeInbound( wrappedBuffer( new byte[]{1, 2, 3, 4, 5} ) ) ); assertTrue( channel.writeInbound( wrappedBuffer( new byte[0] ) ) ); assertTrue( channel.finish() ); assertEquals( 1, channel.inboundMessages().size() ); assertByteBufEquals( wrappedBuffer( new byte[]{1, 2, 3, 4, 5} ), channel.readInbound() ); }
assertTrue( channel.finish() );
@Test public void shouldDecodeMessageWithMultipleChunks() { assertFalse( channel.writeInbound( wrappedBuffer( new byte[]{1, 2, 3} ) ) ); assertFalse( channel.writeInbound( wrappedBuffer( new byte[]{4, 5} ) ) ); assertFalse( channel.writeInbound( wrappedBuffer( new byte[]{6, 7, 8} ) ) ); assertTrue( channel.writeInbound( wrappedBuffer( new byte[0] ) ) ); assertTrue( channel.finish() ); assertEquals( 1, channel.inboundMessages().size() ); assertByteBufEquals( wrappedBuffer( new byte[]{1, 2, 3, 4, 5, 6, 7, 8} ), channel.readInbound() ); }
@Test public void shouldDecodeEmptyChunk() { // chunk contains just the size header which is zero ByteBuf input = copyShort( 0 ); assertTrue( channel.writeInbound( input ) ); assertTrue( channel.finish() ); // there should only be a single chunk available for reading assertEquals( 1, channel.inboundMessages().size() ); // it should have no size header and empty body assertByteBufEquals( wrappedBuffer( new byte[0] ), channel.readInbound() ); }
if (buf == null && endOfStream && channel.finish()) { buf = nextReadableBuf(channel); ByteBuf nextBuf = nextReadableBuf(channel); boolean decompressedEndOfStream = nextBuf == null && endOfStream; if (decompressedEndOfStream && channel.finish()) { nextBuf = nextReadableBuf(channel); decompressedEndOfStream = nextBuf == null;
if (buf == null) { if (endOfStream) { if (channel.finish()) { buf = nextReadableBuf(channel); ByteBuf nextBuf = nextReadableBuf(channel); boolean compressedEndOfStream = nextBuf == null && endOfStream; if (compressedEndOfStream && channel.finish()) { nextBuf = nextReadableBuf(channel); compressedEndOfStream = nextBuf == null;