void encrypt(ByteBuffer src) throws SSLException {
  if (!handshakeComplete) {
    throw new IllegalStateException();
  }
  if (!src.hasRemaining()) {
    if (outNetBuffer == null) {
      outNetBuffer=emptyBuffer;
    }
    return;
  }
  createOutNetBuffer(src.remaining());
  while (src.hasRemaining()) {
    SSLEngineResult result=sslEngine.wrap(src,outNetBuffer.buf());
    if (result.getStatus() == SSLEngineResult.Status.OK) {
      if (result.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NEED_TASK) {
        doTasks();
      }
    }
 else     if (result.getStatus() == SSLEngineResult.Status.BUFFER_OVERFLOW) {
      outNetBuffer.capacity(outNetBuffer.capacity() << 1);
      outNetBuffer.limit(outNetBuffer.capacity());
    }
 else {
      throw new SSLException("SSLEngine error during encrypt: " + result.getStatus() + " src: "+ src+ "outNetBuffer: "+ outNetBuffer);
    }
  }
  outNetBuffer.flip();
}

void encrypt ( ByteBuffer src ) throws SSLException { if ( ! handshakeComplete ) { throw new IllegalStateException ( ) ; } if ( ! src . hasRemaining ( ) ) { if ( outNetBuffer == null ) { outNetBuffer = emptyBuffer ; } return ; } createOutNetBuffer ( src . remaining ( ) ) ; while ( src . hasRemaining ( ) ) { SSLEngineResult result = sslEngine . wrap ( src , outNetBuffer . buf ( ) ) ; if ( result . getStatus ( ) == SSLEngineResult . Status . OK ) { if ( result . getHandshakeStatus ( ) == SSLEngineResult . HandshakeStatus . NEED_TASK ) { doTasks ( ) ; } } else if ( result . getStatus ( ) == SSLEngineResult . Status . BUFFER_OVERFLOW ) { outNetBuffer . capacity ( outNetBuffer . capacity ( ) << 1 ) ; outNetBuffer . limit ( outNetBuffer . capacity ( ) ) ; } else { throw new SSLException ( "SSLEngine error during encrypt: " + result . getStatus ( ) + " src: " + src + "outNetBuffer: " + outNetBuffer ) ; } } outNetBuffer . flip ( ) ; }
encrypt provided buffer . encrypted data returned by getoutnetbuffer ( ) .
