FileDocCategorySizeDatePackage
SSLByteBufferInputStream.javaAPI DocGlassfish v2 API4149Tue Aug 14 18:51:28 BST 2007com.sun.enterprise.web.connector.grizzly.ssl

SSLByteBufferInputStream

public class SSLByteBufferInputStream extends com.sun.enterprise.web.connector.grizzly.ByteBufferInputStream
Stream wrapper around a ByteBuffer. Under the hood, Selector are used to read bytes from the underlying socketChannel.
author
Jean-Francois Arcand

Fields Summary
Constructors Summary
Methods Summary
protected intdoRead()
Read and decrypt bytes from the underlying SSL connections. All the SSLEngine operations are delegated to class SSLUtils.

   
        final SSLWorkerThread workerThread = 
                (SSLWorkerThread)Thread.currentThread();

        byteBuffer.compact();
        
        int initialPosition = byteBuffer.position();
        int byteRead = 0;
        
        // We need to make sure the unwrap worked properly and we have all
        // the packets properly read. If the SSLEngine fail to unwrap all the 
        // bytes, the byteBuffer will be empty event if some encrypted bytes
        // are available. 
        while (byteBuffer.position() == initialPosition){
            int currentRead = SSLUtils.doHandshakeRead(key,workerThread.getInputBB(),
                    workerThread.getSSLEngine(),readTimeout);
            
            if (currentRead > 0) {
                byteRead += currentRead;
            }
            
            if (currentRead > 0 || workerThread.getInputBB().position() > 0) {
                try{
                    byteBuffer = SSLUtils.unwrapAll(byteBuffer,
                            workerThread.getInputBB(),workerThread.getSSLEngine());
                    workerThread.setByteBuffer(byteBuffer);
                } catch (IOException ex){
                    Logger logger = SSLSelectorThread.logger();
                    if ( logger.isLoggable(Level.FINE) )
                        logger.log(Level.FINE,"SSLUtils.unwrapAll",ex);
                    return -1;
                }
            }  else {
                break;
            }   
        }

        byteBuffer.flip();
        return byteRead;