} else {
tempBuffer = readBuffer;
}
boolean done = false;
SSLEngineResult result;
ByteBuffer appBuffer = ByteBuffer.allocateDirect(sslEngine.getSession().getApplicationBufferSize());
HandshakeStatus handshakeStatus = sslEngine.getHandshakeStatus();
while (!done) {
switch (handshakeStatus) {
case NEED_UNWRAP:
case NOT_HANDSHAKING:
case FINISHED:
result = sslEngine.unwrap(tempBuffer, appBuffer);
handshakeStatus = result.getHandshakeStatus();
switch (result.getStatus()) {
case BUFFER_UNDERFLOW:
/* we need more data */
done = true;
break;
case BUFFER_OVERFLOW:
/* resize output buffer */
appBuffer = ByteBuffer.allocateDirect(appBuffer.capacity() * 2);
break;
case OK:
if ((handshakeStatus == HandshakeStatus.NOT_HANDSHAKING) && (result.bytesProduced() > 0)) {
appBuffer.flip();
session.processMessageReceived(appBuffer);
}
}
break;
case NEED_TASK:
Runnable task;
while ((task = sslEngine.getDelegatedTask()) != null) {
task.run();
}
handshakeStatus = sslEngine.getHandshakeStatus();
break;
case NEED_WRAP:
result = sslEngine.wrap(EMPTY_BUFFER, appBuffer);
handshakeStatus = result.getHandshakeStatus();
switch (result.getStatus()) {
case BUFFER_OVERFLOW:
appBuffer = ByteBuffer.allocateDirect(appBuffer.capacity() * 2);
break;
case BUFFER_UNDERFLOW:
done = true;