+
+ private void initChunk() {
+ chunk = Unpooled.compositeBuffer();
+ }
+
+ private void aggregateChunks(ByteBuf newChunk) {
+ chunk.addComponent(chunk.numComponents(), newChunk);
+
+ // Update writer index, addComponent does not update it
+ chunk.writerIndex(chunk.writerIndex() + newChunk.readableBytes());
+ }
+
+ private static int processHeaderLengthFirst(byte b) {
+ if (isHeaderLengthFirst(b) == false) {
+ logger.debug("Got byte {} while waiting for {}-{}", b, (byte)'1', (byte)'9');
+ throw new IllegalStateException("Invalid chunk size encountered (byte 0)");
+ }
+
+ return b - '0';
+ }
+
+ private static boolean isHeaderLengthFirst(byte b) {
+ return b >= '1' && b <= '9';
+ }