throw new UnsupportedOperationException();
}
if (isClosing() || !isConnected()) {
WriteFuture future = new DefaultWriteFuture(this);
WriteRequest request = new DefaultWriteRequest(message, future, remoteAddress);
future.setException(new WriteToClosedSessionException(request));
return future;
}
FileChannel openedFileChannel = null;
try {
if (message instanceof IoBuffer
&& !((IoBuffer) message).hasRemaining()) {
throw new IllegalArgumentException(
"message is empty. Forgot to call flip()?");
} else if (message instanceof FileChannel) {
FileChannel fileChannel = (FileChannel) message;
message = new DefaultFileRegion(fileChannel, 0, fileChannel.size());
} else if (message instanceof File) {
File file = (File) message;
openedFileChannel = new FileInputStream(file).getChannel();
message = new DefaultFileRegion(openedFileChannel, 0, openedFileChannel.size());
}
} catch (IOException e) {
ExceptionMonitor.getInstance().exceptionCaught(e);
return DefaultWriteFuture.newNotWrittenFuture(this, e);
}
WriteFuture future = new DefaultWriteFuture(this);
getFilterChain().fireFilterWrite(
new DefaultWriteRequest(message, future, remoteAddress));
if (openedFileChannel != null) {
// If we opened a FileChannel, it needs to be closed when the write has completed
final FileChannel finalChannel = openedFileChannel;
future.addListener(new IoFutureListener<WriteFuture>() {