Merge pull request #554 from jfallows/composite-buffer

Prevent Unpooled.EMPTY_BUFFER from being stored in the composite buffer ...
This commit is contained in:
Norman Maurer 2012-08-23 22:26:03 -07:00
commit 5dbb799a92

View File

@ -1166,12 +1166,17 @@ public class DefaultCompositeByteBuf extends AbstractByteBuf implements Composit
} }
components.subList(0, firstComponentId).clear(); components.subList(0, firstComponentId).clear();
// Replace the first readable component with a new slice. // Remove or replace the first readable component with a new slice.
Component c = components.get(0); Component c = components.get(0);
int adjustment = readerIndex - c.offset; int adjustment = readerIndex - c.offset;
Component newC = new Component(c.buf.slice(adjustment, c.length - adjustment)); if (adjustment == c.length) {
c.buf.unsafe().release(); // new slice would be empty, so remove instead
components.set(0, newC); components.remove(0);
} else {
Component newC = new Component(c.buf.slice(adjustment, c.length - adjustment));
c.buf.unsafe().release();
components.set(0, newC);
}
// Update indexes and markers. // Update indexes and markers.
updateComponentOffsets(0); updateComponentOffsets(0);