if (e.getMessage() instanceof ChunkedInput) {
ctx.sendDownstream(evt);
return;
}
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();
encoded.setInt(0, encoded.writerIndex() - 4);
write(ctx, e.getFuture(), encoded, e.getRemoteAddress());
for (InputStream is : oout.getStreams()) {
Channels.write(ctx.getChannel(), new AnonymousChunkedStream(new BufferedInputStream(is, CHUNK_SIZE)));
}