src/main/java/com/hibegin/http/server/handler/SSLReadWriteSelectorHandler.java
ByteBuffer read() throws IOException {
        SSLEngineResult result;

        if (!initialHSComplete) {
            throw new IllegalStateException();
        }

        int pos = requestBB.position();

        if (sc.read(inNetBB) == -1) {
            sslEngine.closeInbound();  // probably throws exception
            throw new EOFException();
        }

        do {
            resizeRequestBB(inNetBB.remaining());    // guarantees enough room for unwrap
            inNetBB.flip();
            result = sslEngine.unwrap(inNetBB, requestBB);
            inNetBB.compact();

	    /*
         * Could check here for a renegotation, but we're only
	     * doing a simple read/write, and won't have enough state
	     * transitions to do a complete handshake, so ignore that
	     * possibility.
	     */
            switch (result.getStatus()) {

                case BUFFER_UNDERFLOW:
                case OK:
                    if (result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
                        doTasks();
                    }
                    break;

                default:
                    throw new IOException("sslEngine error during data read: " +
                            result.getStatus());
            }
        } while ((inNetBB.position() != 0) &&
                result.getStatus() != Status.BUFFER_UNDERFLOW);
        int readLength = requestBB.position() - pos;
        ByteBuffer byteBuffer = ByteBuffer.allocate(readLength);
        byteBuffer.put(BytesUtil.subBytes(requestBB.array(), pos, readLength));
        return byteBuffer;
    }
ByteBuffer read() throws IOException {
        SSLEngineResult result;

        if (!initialHSComplete) {
            throw new IllegalStateException();
        }

        int pos = requestBB.position();

        if (sc.read(inNetBB) == -1) {
            sslEngine.closeInbound();  // probably throws exception
            throw new EOFException();
        }

        do {
            resizeRequestBB(inNetBB.remaining());    // guarantees enough room for unwrap
            inNetBB.flip();
            result = sslEngine.unwrap(inNetBB, requestBB);
            inNetBB.compact();

	    /*
         * Could check here for a renegotation, but we're only
	     * doing a simple read/write, and won't have enough state
	     * transitions to do a complete handshake, so ignore that
	     * possibility.
	     */
            switch (result.getStatus()) {

                case BUFFER_UNDERFLOW:
                case OK:
                    if (result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
                        doTasks();
                    }
                    break;

                default:
                    throw new IOException("sslEngine error during data read: " +
                            result.getStatus());
            }
        } while ((inNetBB.position() != 0) &&
                result.getStatus() != Status.BUFFER_UNDERFLOW);
        int readLength = requestBB.position() - pos;
        ByteBuffer byteBuffer = ByteBuffer.allocate(readLength);
        byteBuffer.put(BytesUtil.subBytes(requestBB.array(), pos, readLength));
        return byteBuffer;
    }
ByteBuffer read ( ) throws IOException { SSLEngineResult result ; if ( ! initialHSComplete ) { throw new IllegalStateException ( ) ; } int pos = requestBB . position ( ) ; if ( sc . read ( inNetBB ) == - 1 ) { sslEngine . closeInbound ( ) ; // probably throws exception throw new EOFException ( ) ; } do { resizeRequestBB ( inNetBB . remaining ( ) ) ; // guarantees enough room for unwrap inNetBB . flip ( ) ; result = sslEngine . unwrap ( inNetBB , requestBB ) ; inNetBB . compact ( ) ; /*
         * Could check here for a renegotation, but we're only
	     * doing a simple read/write, and won't have enough state
	     * transitions to do a complete handshake, so ignore that
	     * possibility.
	     */ switch ( result . getStatus ( ) ) { case BUFFER_UNDERFLOW : case OK : if ( result . getHandshakeStatus ( ) == HandshakeStatus . NEED_TASK ) { doTasks ( ) ; } break ; default : throw new IOException ( "sslEngine error during data read: " + result . getStatus ( ) ) ; } } while ( ( inNetBB . position ( ) != 0 ) && result . getStatus ( ) != Status . BUFFER_UNDERFLOW ) ; int readLength = requestBB . position ( ) - pos ; ByteBuffer byteBuffer = ByteBuffer . allocate ( readLength ) ; byteBuffer . put ( BytesUtil . subBytes ( requestBB . array ( ) , pos , readLength ) ) ; return byteBuffer ; }
/*
Read the channel for more information, then unwrap the
(hopefully application) data we get.
<P>
If we run out of data, we'll return to our caller (possibly using
a Selector) to get notification that more is available.
<P>
Each call to this method will perform at most one underlying read().
/ * Read the channel for more information then unwrap the ( hopefully application ) data we get . <P > If we run out of data we ll return to our caller ( possibly using a Selector ) to get notification that more is available . <P > Each call to this method will perform at most one underlying read () .