Here you can find the source of write(WritableByteChannel socketChannel, SSLEngine engine, ByteBuffer plainOut, ByteBuffer cypherOut)
public static void write(WritableByteChannel socketChannel, SSLEngine engine, ByteBuffer plainOut, ByteBuffer cypherOut) throws IOException
//package com.java2s; // This software, the RabbitMQ Java client library, is triple-licensed under the import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngineResult; import javax.net.ssl.SSLException; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.WritableByteChannel; public class Main { public static void write(WritableByteChannel socketChannel, SSLEngine engine, ByteBuffer plainOut, ByteBuffer cypherOut) throws IOException { while (plainOut.hasRemaining()) { cypherOut.clear();//from w w w.jav a 2 s. c om SSLEngineResult result = engine.wrap(plainOut, cypherOut); switch (result.getStatus()) { case OK: cypherOut.flip(); while (cypherOut.hasRemaining()) { socketChannel.write(cypherOut); } break; case BUFFER_OVERFLOW: throw new SSLException("Buffer overflow occured after a wrap."); case BUFFER_UNDERFLOW: throw new SSLException("Buffer underflow occured after a wrap."); case CLOSED: throw new SSLException("Buffer closed"); default: throw new IllegalStateException("Invalid SSL status: " + result.getStatus()); } } } private static SSLEngineResult.HandshakeStatus wrap(ByteBuffer plainOut, ByteBuffer cipherOut, WritableByteChannel channel, SSLEngine sslEngine) throws IOException { SSLEngineResult.HandshakeStatus handshakeStatus = sslEngine.getHandshakeStatus(); SSLEngineResult.Status status = sslEngine.wrap(plainOut, cipherOut).getStatus(); switch (status) { case OK: handshakeStatus = runDelegatedTasks(sslEngine); cipherOut.flip(); while (cipherOut.hasRemaining()) { channel.write(cipherOut); } cipherOut.clear(); break; case BUFFER_OVERFLOW: throw new SSLException("Buffer overflow during handshake"); default: throw new SSLException("Unexpected status " + status); } return handshakeStatus; } private static SSLEngineResult.HandshakeStatus runDelegatedTasks(SSLEngine sslEngine) { // FIXME run in executor? Runnable runnable; while ((runnable = sslEngine.getDelegatedTask()) != null) { runnable.run(); } return sslEngine.getHandshakeStatus(); } }