ChannelBufferOutputStream bout =
new ChannelBufferOutputStream(dynamicBuffer(
estimatedLength, ctx.getChannel().getConfig().getBufferFactory()));
bout.write(LENGTH_PLACEHOLDER);
final CompactObjectOutputStream oout = new CompactObjectOutputStream(bout);
oout.writeObject(e.getMessage());
ExternalizeUtil.writeCollection(oout, oout.getReferences());
oout.flush();
oout.close();
ChannelBuffer encoded = bout.buffer();