Allow to @override the cumulative ChannelBuffer creation. See #169

This commit is contained in:
Norman Maurer 2012-01-31 20:17:09 +01:00
parent 5a91bd36c4
commit 02f49af3a1

View File

@ -363,10 +363,20 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler {
private ChannelBuffer cumulation(ChannelHandlerContext ctx) { private ChannelBuffer cumulation(ChannelHandlerContext ctx) {
ChannelBuffer c = cumulation; ChannelBuffer c = cumulation;
if (c == null) { if (c == null) {
c = ChannelBuffers.dynamicBuffer( c = createCumulationDynamicBuffer(ctx);
ctx.getChannel().getConfig().getBufferFactory());
cumulation = c; cumulation = c;
} }
return c; return c;
} }
/**
* Create a new {@link ChannelBuffer} which is used for the cumulation. Be aware that this MUST be a dynamic buffer. Sub-classes may override this to provide a
* dynamic {@link ChannelBuffer} which has some prelocated size that better fit their need.
*
* @param ctx {@link ChannelHandlerContext} for this handler
* @return buffer the {@link ChannelBuffer} which is used for cumulation
*/
protected ChannelBuffer createCumulationDynamicBuffer(ChannelHandlerContext ctx) {
return ChannelBuffers.dynamicBuffer(ctx.getChannel().getConfig().getBufferFactory());
}
} }