From 02f49af3a1046ed1ab5d5d19e88962fcfc71da0b Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Tue, 31 Jan 2012 20:17:09 +0100 Subject: [PATCH] Allow to @override the cumulative ChannelBuffer creation. See #169 --- .../io/netty/handler/codec/frame/FrameDecoder.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/codec/src/main/java/io/netty/handler/codec/frame/FrameDecoder.java b/codec/src/main/java/io/netty/handler/codec/frame/FrameDecoder.java index 9c2ac67e2e3a..73c797191bdd 100644 --- a/codec/src/main/java/io/netty/handler/codec/frame/FrameDecoder.java +++ b/codec/src/main/java/io/netty/handler/codec/frame/FrameDecoder.java @@ -363,10 +363,20 @@ private void cleanup(ChannelHandlerContext ctx, ChannelStateEvent e) private ChannelBuffer cumulation(ChannelHandlerContext ctx) { ChannelBuffer c = cumulation; if (c == null) { - c = ChannelBuffers.dynamicBuffer( - ctx.getChannel().getConfig().getBufferFactory()); + c = createCumulationDynamicBuffer(ctx); cumulation = 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()); + } }