org.glassfish.grizzly.http.server.io
Class NIOInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.glassfish.grizzly.http.server.io.NIOInputStream
All Implemented Interfaces:
java.io.Closeable, BinaryNIOInputSource, NIOInputSource

public class NIOInputStream
extends java.io.InputStream
implements BinaryNIOInputSource

Stream implementation to read binary request content.

Since:
2.0

Constructor Summary
NIOInputStream(InputBuffer inputBuffer)
          Constructs a new NIOInputStream using the specified inputBuffer
 
Method Summary
 int available()
          
 void close()
          
 Buffer getBuffer()
           Returns the underlying Buffer that backs this NIOInputSource.
 boolean isFinished()
          
 boolean isReady()
          
 void mark(int readlimit)
          
 boolean markSupported()
          This InputStream implementation supports marking.
 boolean notifyAvailable(ReadHandler handler)
           Notify the specified ReadHandler when any number of bytes can be read without blocking.
 boolean notifyAvailable(ReadHandler handler, int size)
           Notify the specified ReadHandler when the number of bytes that can be read without blocking is greater or equal to the specified size.
 int read()
          
 int read(byte[] b)
          
 int read(byte[] b, int off, int len)
          
 int readyData()
          
 void reset()
          
 long skip(long n)
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NIOInputStream

public NIOInputStream(InputBuffer inputBuffer)
Constructs a new NIOInputStream using the specified inputBuffer

Parameters:
inputBuffer - the InputBuffer from which binary content will be supplied
Method Detail

read

public int read()
         throws java.io.IOException

Specified by:
read in class java.io.InputStream
Throws:
java.io.IOException

read

public int read(byte[] b)
         throws java.io.IOException

Overrides:
read in class java.io.InputStream
Throws:
java.io.IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException

Overrides:
read in class java.io.InputStream
Throws:
java.io.IOException

skip

public long skip(long n)
          throws java.io.IOException

Overrides:
skip in class java.io.InputStream
Throws:
java.io.IOException

available

public int available()
              throws java.io.IOException

Overrides:
available in class java.io.InputStream
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.InputStream
Throws:
java.io.IOException

mark

public void mark(int readlimit)

Overrides:
mark in class java.io.InputStream

reset

public void reset()
           throws java.io.IOException

Overrides:
reset in class java.io.InputStream
Throws:
java.io.IOException

markSupported

public boolean markSupported()
This InputStream implementation supports marking.

Overrides:
markSupported in class java.io.InputStream
Returns:
true

notifyAvailable

public boolean notifyAvailable(ReadHandler handler)

Notify the specified ReadHandler when any number of bytes can be read without blocking.

Invoking this method is equivalent to calling: notifyAvailable(handler, 0).

Specified by:
notifyAvailable in interface NIOInputSource
Parameters:
handler - the ReadHandler to notify.
Returns:
true if the specified handler has been accepted and will be notified as data becomes available to write, otherwise returns false which means data is available to be read without blocking.
See Also:
ReadHandler.onDataAvailable(), ReadHandler.onAllDataRead()

notifyAvailable

public boolean notifyAvailable(ReadHandler handler,
                               int size)

Notify the specified ReadHandler when the number of bytes that can be read without blocking is greater or equal to the specified size.

Specified by:
notifyAvailable in interface NIOInputSource
Parameters:
handler - the ReadHandler to notify.
size - the least number of bytes that must be available before the ReadHandler is invoked. If size is 0, the handler will be notified as soon as data is available no matter the size.
Returns:
true if the specified handler has been accepted and will be notified as data becomes available to write, otherwise returns false which means data is available to be read without blocking.
See Also:
ReadHandler.onDataAvailable(), ReadHandler.onAllDataRead()

isFinished

public boolean isFinished()

Specified by:
isFinished in interface NIOInputSource
Returns:
true when all data for this particular request has been read, otherwise returns false.

readyData

public int readyData()

Specified by:
readyData in interface NIOInputSource
Returns:
the number of bytes (or characters) that may be obtained without blocking. Note when dealing with characters, this method will return an estimate on the number of characters available.

isReady

public boolean isReady()

Specified by:
isReady in interface NIOInputSource
Returns:
true if data can be obtained without blocking, otherwise returns false.

getBuffer

public Buffer getBuffer()

Returns the underlying Buffer that backs this NIOInputSource.

Specified by:
getBuffer in interface BinaryNIOInputSource
Returns:
the underlying Buffer that backs this NIOInputSource.


Copyright © 2011 Oracle Corpration. All Rights Reserved.