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:
Daniel Bevenius 2014-07-02 16:11:00 +02:00 committed by Norman Maurer
parent 812e1719d7
commit 43bfc244cf

View File

@ -125,7 +125,7 @@ public class Http2ClientConnectionHandler extends AbstractHttp2ConnectionHandler
int available = data.readableBytes(); int available = data.readableBytes();
if (collectedData == null) { if (collectedData == null) {
collectedData = ctx().alloc().buffer(available); collectedData = ctx().alloc().buffer(available);
collectedData.writeBytes(data); collectedData.writeBytes(data, data.readerIndex(), data.readableBytes());
} else { } else {
// Expand the buffer // Expand the buffer
ByteBuf newBuffer = ctx().alloc().buffer(collectedData.readableBytes() + available); 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 it's the last frame, print the complete message.
if (endOfStream) { if (endOfStream) {
byte[] bytes = new byte[data.readableBytes()]; System.out.println("Received message: " + collectedData.toString(CharsetUtil.UTF_8));
data.readBytes(bytes);
System.out.println("Received message: " + new String(bytes, CharsetUtil.UTF_8));
// Free the data buffer. // Free the data buffer.
collectedData.release(); collectedData.release();