com.sun.enterprise.web.connector.grizzly
Class ByteBufferInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by com.sun.enterprise.web.connector.grizzly.ByteBufferInputStream
All Implemented Interfaces:
Closeable
Direct Known Subclasses:
CometInputStream, SSLAsyncStream, SSLByteBufferInputStream

public class ByteBufferInputStream
extends InputStream

This class implement IO stream operations on top of a ByteBuffer. Under the hood, this class use a temporary Selector pool to for reading bytes when the client ask for more and the current Selector is not yet ready.

Author:
Jeanfrancois Arcand

Field Summary
protected  ByteBuffer byteBuffer
          The wrapped ByteBuffer
protected  SelectionKey key
          The SelectionKey used by this stream.
protected  int readTimeout
          The time to wait before timing out when reading bytes
protected  int readTry
          Number of times to retry before return EOF
 
Constructor Summary
ByteBufferInputStream()
           
ByteBufferInputStream(ByteBuffer byteBuffer)
           
 
Method Summary
 int available()
          Return the available bytes
 void close()
          Close this stream.
protected  int doRead()
          Read bytes using the read ReadSelector
 ByteBuffer getByteBuffer()
          Get the wrapped ByteBuffer
static int getDefaultReadTimeout()
           
 int getReadTimeout()
          Return the timeout between two consecutives Selector.select() when a temporary Selector is used.
 boolean markSupported()
          Return true if mark is supported.
 int read()
          Read the first byte from the wrapped ByteBuffer.
 int read(byte[] b)
          Read the bytes from the wrapped ByteBuffer.
 int read(byte[] b, int offset, int length)
          Read the first byte of the wrapped ByteBuffer.
 int read(ByteBuffer bb)
          Read the first byte of the wrapped ByteBuffer.
static int readBlocking(SocketChannel socketChannel, ByteBuffer byteBuffer, int readTimeout)
           
 void recycle()
          Recycle this object.
 void setByteBuffer(ByteBuffer byteBuffer)
          Set the wrapped ByteBuffer
static void setDefaultReadTimeout(int aDefaultReadTimeout)
           
 void setReadTimeout(int rt)
          Set the timeout between two consecutives Selector.select() when a temporary Selector is used.
 void setSelectionKey(SelectionKey key)
          Set the SelectionKey used to reads bytes.
 
Methods inherited from class java.io.InputStream
mark, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

byteBuffer

protected ByteBuffer byteBuffer
The wrapped ByteBuffer

key

protected SelectionKey key
The SelectionKey used by this stream.


readTimeout

protected int readTimeout
The time to wait before timing out when reading bytes


readTry

protected int readTry
Number of times to retry before return EOF

Constructor Detail

ByteBufferInputStream

public ByteBufferInputStream()

ByteBufferInputStream

public ByteBufferInputStream(ByteBuffer byteBuffer)
Method Detail

setByteBuffer

public void setByteBuffer(ByteBuffer byteBuffer)
Set the wrapped ByteBuffer

Parameters:
byteBuffer - The wrapped byteBuffer

getByteBuffer

public ByteBuffer getByteBuffer()
Get the wrapped ByteBuffer


available

public int available()
Return the available bytes

Overrides:
available in class InputStream
Returns:
the wrapped byteBuffer.remaining()

close

public void close()
Close this stream.

Specified by:
close in interface Closeable
Overrides:
close in class InputStream

markSupported

public boolean markSupported()
Return true if mark is supported.

Overrides:
markSupported in class InputStream

read

public int read()
         throws IOException
Read the first byte from the wrapped ByteBuffer.

Specified by:
read in class InputStream
Throws:
IOException

read

public int read(byte[] b)
         throws IOException
Read the bytes from the wrapped ByteBuffer.

Overrides:
read in class InputStream
Throws:
IOException

read

public int read(byte[] b,
                int offset,
                int length)
         throws IOException
Read the first byte of the wrapped ByteBuffer.

Overrides:
read in class InputStream
Throws:
IOException

read

public int read(ByteBuffer bb)
         throws IOException
Read the first byte of the wrapped ByteBuffer.

Throws:
IOException

recycle

public void recycle()
Recycle this object.


setSelectionKey

public void setSelectionKey(SelectionKey key)
Set the SelectionKey used to reads bytes.


doRead

protected int doRead()
              throws IOException
Read bytes using the read ReadSelector

Throws:
IOException

getReadTimeout

public int getReadTimeout()
Return the timeout between two consecutives Selector.select() when a temporary Selector is used.


setReadTimeout

public void setReadTimeout(int rt)
Set the timeout between two consecutives Selector.select() when a temporary Selector is used.


getDefaultReadTimeout

public static int getDefaultReadTimeout()

setDefaultReadTimeout

public static void setDefaultReadTimeout(int aDefaultReadTimeout)

readBlocking

public static int readBlocking(SocketChannel socketChannel,
                               ByteBuffer byteBuffer,
                               int readTimeout)
                        throws IOException
Throws:
IOException


Copyright © 2005-2015 Oracle Corporation. All Rights Reserved.