use of org.apache.mina.core.write.DefaultWriteRequest in project zm-mailbox by Zimbra.
the class SaslFilter method filterWrite.
@Override
public void filterWrite(NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws IOException {
IoBuffer buf = (IoBuffer) writeRequest.getMessage();
// has been sent to client.
if (session.containsAttribute(DISABLE_ENCRYPTION_ONCE)) {
debug("filterWrite: before encryption size = %d", buf.remaining());
session.removeAttribute(DISABLE_ENCRYPTION_ONCE);
nextFilter.filterWrite(session, writeRequest);
return;
}
// Encrypt input buffer
debug("filterWrite: message size = %d", buf.remaining());
if (buf.remaining() == 0) {
// Some clients (i.e. imtest) choke upon receiving an empty block
debug("filterWrite: skipping encryption of empty buffer");
nextFilter.filterWrite(session, writeRequest);
return;
}
List<IoBuffer> buffers = encrypt(buf);
buf.clear();
// Create and send new WriteRequest for each output buffer. The last
// request includes the WriteFuture from the original request, and this
// ensures correctness of the WriteFuture since the earlier requests
// will have been written before the last.
int size = buffers.size();
for (int i = 0; i < size - 1; i++) {
nextFilter.filterWrite(session, new DefaultWriteRequest(buffers.get(i)));
}
nextFilter.filterWrite(session, new DefaultWriteRequest(buffers.get(size - 1), writeRequest.getFuture()));
}
Aggregations