Changed Http2ClientConnectionHandler to print out the aggregated buffers content
Motivation: When running the Http2Client the data returned from the server, the "Hello World" string, is supposed to be printed but instead the following is displayed: Received message: Modifications: Use the aggregated buffer to print out. Result: The example now logs the correct data sent from the server: Received message: Hello World
This commit is contained in:
parent
812e1719d7
commit
43bfc244cf
@ -125,7 +125,7 @@ public class Http2ClientConnectionHandler extends AbstractHttp2ConnectionHandler
|
||||
int available = data.readableBytes();
|
||||
if (collectedData == null) {
|
||||
collectedData = ctx().alloc().buffer(available);
|
||||
collectedData.writeBytes(data);
|
||||
collectedData.writeBytes(data, data.readerIndex(), data.readableBytes());
|
||||
} else {
|
||||
// Expand the buffer
|
||||
ByteBuf newBuffer = ctx().alloc().buffer(collectedData.readableBytes() + available);
|
||||
@ -137,9 +137,7 @@ public class Http2ClientConnectionHandler extends AbstractHttp2ConnectionHandler
|
||||
|
||||
// If it's the last frame, print the complete message.
|
||||
if (endOfStream) {
|
||||
byte[] bytes = new byte[data.readableBytes()];
|
||||
data.readBytes(bytes);
|
||||
System.out.println("Received message: " + new String(bytes, CharsetUtil.UTF_8));
|
||||
System.out.println("Received message: " + collectedData.toString(CharsetUtil.UTF_8));
|
||||
|
||||
// Free the data buffer.
|
||||
collectedData.release();
|
||||
|
Loading…
Reference in New Issue
Block a user