## com.sun.grizzly.util
Class InputReader

    java.lang.Object
      java.io.InputStream
          com.sun.grizzly.util.InputReader

All Implemented Interfaces:
  Closeable

Direct Known Subclasses:
  ByteBufferInputStream

    public class InputReader

extends InputStream

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

Author:
  Jeanfrancois Arcand

Nested Class Summary
`static class` `InputReader.ChannelType` The `Channel` type is used to avoid invoking the instanceof operation when registering the Socket|Datagram Channel to the Selector.

Field Summary
`protected ByteBuffer` `byteBuffer` The wrapped `ByteBuffer</code<</TD>`
`protected SelectionKey` `key` The `SelectionKey` used by this stream.
`protected int` `readTimeout` The time to wait before timing out when reading bytes

Constructor Summary
`InputReader()`
`InputReader(ByteBuffer byteBuffer)`

Method Summary
`int` `available()` Return the available bytes
`void` `close()` Close this stream.
`protected int` `doClearRead()`
`protected int` `doRead()` Read bytes using the read `ReadSelector`
`protected int` `doSecureRead()` Read and decrypt bytes from the underlying SSL connections.
`ByteBuffer` `getByteBuffer()` Get the wrapped `ByteBuffer`
`InputReader.ChannelType` `getChannelType()` Return the `Channel` type.
`static int` `getDefaultReadTimeout()` Return the Selector.select() default time out.
`int` `getReadTimeout()` Return the timeout between two consecutives Selector.select() when a temporary Selector is used.
`boolean` `isSecure()` Is this Stream secure.
`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 bytes of the wrapped `ByteBuffer`.
`void` `recycle()` Recycle this object.
`void` `setByteBuffer(ByteBuffer byteBuffer)` Set the wrapped `ByteBuffer`
`void` `setChannelType(InputReader.ChannelType channelType)` Set the `Channel` type, which is ocketChannel or DatagramChannel.
`static void` `setDefaultReadTimeout(int aDefaultReadTimeout)` Set the default Selector.select() time out.
`void` `setReadTimeout(int rt)` Set the timeout between two consecutives Selector.select() when a temporary Selector is used.
`void` `setSecure(boolean secure)` Set this stream secure.
`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</code< <P>
  `

### key

    protected SelectionKey key

  The `SelectionKey` used by this stream.

### readTimeout

    protected int readTimeout

  The time to wait before timing out when reading bytes

Constructor Detail

### InputReader

    public InputReader()

### InputReader

    public InputReader(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`

  Returns:
    `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`
  Parameters:
    `offset` -
    `length` -
  Throws:
    `IOException`

### read

    public int read(ByteBuffer bb)
             throws IOException

  Read the bytes of the wrapped `ByteBuffer`.

  Parameters:
    `bb` - `ByteBuffer`
  Returns:
    - number of bytes read
  Throws:
    `IOException`

### recycle

    public void recycle()

  Recycle this object.

### setSelectionKey

    public void setSelectionKey(SelectionKey key)

  Set the `SelectionKey` used to reads bytes.

  Parameters:
    `key` - `SelectionKey`

### doRead

    protected int doRead()
                  throws IOException

  Read bytes using the read `ReadSelector`

  Returns:
    - number of bytes read
  Throws:
    `IOException`

### doSecureRead

    protected int doSecureRead()
                        throws IOException

  Read and decrypt bytes from the underlying SSL connections. All the SSLEngine operations are delegated to class `SSLUtils`.

  Returns:
    number of bytes read
  Throws:
    `IOException`

### doClearRead

    protected int doClearRead()
                       throws IOException

  Throws:
    `IOException`

### getReadTimeout

    public int getReadTimeout()

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

  Returns:
    read timeout being used

### setReadTimeout

    public void setReadTimeout(int rt)

  Set the timeout between two consecutives Selector.select() when a temporary Selector is used.

  Parameters:
    `rt` - - read timeout

### getDefaultReadTimeout

    public static int getDefaultReadTimeout()

  Return the Selector.select() default time out.

  Returns:
    default time out

### setDefaultReadTimeout

    public static void setDefaultReadTimeout(int aDefaultReadTimeout)

  Set the default Selector.select() time out.

  Parameters:
    `aDefaultReadTimeout` - time out value

### getChannelType

    public InputReader.ChannelType getChannelType()

  Return the `Channel` type. The return value is SocketChannel or DatagramChannel.

  Returns:
    `Channel` being used

### setChannelType

    public void setChannelType(InputReader.ChannelType channelType)

  Set the `Channel` type, which is ocketChannel or DatagramChannel.

  Parameters:
    `channelType` - `Channel` to use

### isSecure

    public boolean isSecure()

  Is this Stream secure.

  Returns:
    true is stream is secure, otherwise false

### setSecure

    public void setSecure(boolean secure)

  Set this stream secure.

  Parameters:
    `secure` - true to set stream secure, otherwise false

Copyright © 2008 SUN Microsystems. All Rights Reserved.