int length = 0;
// Add support to write a FileRegion. This in fact will not give any performance gain
// but at least it not fail and we did the best to emulate it
if (message instanceof FileRegion) {
FileRegion fr = (FileRegion) message;
try {
synchronized (out) {
WritableByteChannel bchannel = Channels.newChannel(out);
long i;
while ((i = fr.transferTo(bchannel, length)) > 0) {
length += i;
if (length >= fr.getCount()) {
break;
}
}
}
} finally {
if (fr instanceof DefaultFileRegion) {
DefaultFileRegion dfr = (DefaultFileRegion) fr;
if (dfr.releaseAfterTransfer()) {
fr.releaseExternalResources();
}
}
}
} else {
ChannelBuffer a = (ChannelBuffer) message;