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

java.lang.Object
  extended by org.glassfish.grizzly.http.server.io.InputBuffer

public class InputBuffer
extends java.lang.Object

Abstraction exposing both byte and character methods to read content from the HTTP messaging system in Grizzly.


Constructor Summary
InputBuffer()
           
 
Method Summary
 boolean append(Buffer buffer)
          Appends the specified Buffer to the internal composite Buffer.
 int available()
           
 int availableChar()
           
 void close()
           
 void fillFully(int length)
          Fill the buffer (blocking) up to the requested length.
 void finished()
          When invoked, this method will call ReadHandler.onAllDataRead() on the current ReadHandler (if any).
 Buffer getBuffer()
           
 ReadHandler getReadHandler()
           
 void initialize(Request serverRequest, FilterChainContext ctx)
           Per-request initialization required for the InputBuffer to function properly.
 boolean isAsyncEnabled()
           
 boolean isClosed()
           
 boolean isFinished()
           
 void mark(int readAheadLimit)
           Supported with binary and character data.
 boolean markSupported()
           Only supported with binary data.
 void notifyAvailable(ReadHandler handler)
          Installs a ReadHandler that will be notified when any data becomes available to read without blocking.
 void notifyAvailable(ReadHandler handler, int size)
          Installs a ReadHandler that will be notified when the specified amount of data is available to be read without blocking.
 void processingChars()
           This method should be called if the InputBuffer is being used in conjunction with a Reader implementation.
 int read(byte[] b, int off, int len)
           
 int read(char[] cbuf, int off, int len)
           
 int read(java.nio.CharBuffer target)
           
 Buffer readBuffer()
           
 int readByte()
          This method always blocks.
 int readChar()
           
 boolean ready()
           
 int readyData()
          Depending on the InputBuffer mode, method will return either number of available bytes or characters ready to be read without blocking.
 void recycle()
           Recycle this InputBuffer for reuse.
 void reset()
           Only supported with binary data.
 void setAsyncEnabled(boolean asyncEnabled)
          Sets the asynchronous processing state of this InputBuffer.
 void setDefaultEncoding(java.lang.String encoding)
          Set the default character encoding for this InputBuffer, which would be applied if no encoding was explicitly set on HTTP Request and character decoding wasn't started yet.
 long skip(long n, boolean block)
          Skips the specified number of bytes/characters.
 void terminate()
           Invoke ReadHandler.onError(Throwable) (assuming a ReadHandler is available) } passing a {#link CancellationException} if the current Connection is open, or a {#link EOFException} if the connection was unexpectedly closed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InputBuffer

public InputBuffer()
Method Detail

initialize

public void initialize(Request serverRequest,
                       FilterChainContext ctx)

Per-request initialization required for the InputBuffer to function properly.

Parameters:
request - the current request
ctx - the FilterChainContext for the chain processing this request

setDefaultEncoding

public void setDefaultEncoding(java.lang.String encoding)
Set the default character encoding for this InputBuffer, which would be applied if no encoding was explicitly set on HTTP Request and character decoding wasn't started yet.


recycle

public void recycle()

Recycle this InputBuffer for reuse.


processingChars

public void processingChars()

This method should be called if the InputBuffer is being used in conjunction with a Reader implementation. If this method is not called, any character-based methods called on this InputBuffer will throw a IllegalStateException.


readByte

public int readByte()
             throws java.io.IOException
This method always blocks.

Throws:
java.io.IOException
See Also:
InputStream.read()

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Throws:
java.io.IOException
See Also:
InputStream.read(byte[], int, int)

readyData

public int readyData()
Depending on the InputBuffer mode, method will return either number of available bytes or characters ready to be read without blocking.

Returns:
depending on the InputBuffer mode, method will return either number of available bytes or characters ready to be read without blocking.

available

public int available()
See Also:
InputStream.available()

getBuffer

public Buffer getBuffer()
Returns:
the underlying Buffer used to buffer incoming request data.

readBuffer

public Buffer readBuffer()
Returns:
the underlying Buffer used to buffer incoming request data. Unlike getBuffer(), this method detaches the returned Buffer, so user code becomes responsible for handling the Buffer.

getReadHandler

public ReadHandler getReadHandler()
Returns:
the ReadHandler current in use, if any.

read

public int read(java.nio.CharBuffer target)
         throws java.io.IOException
Throws:
java.io.IOException
See Also:
Reader.read(java.nio.CharBuffer)

readChar

public int readChar()
             throws java.io.IOException
Throws:
java.io.IOException
See Also:
Reader.read()

read

public int read(char[] cbuf,
                int off,
                int len)
         throws java.io.IOException
Throws:
java.io.IOException
See Also:
Reader.read(char[], int, int)

ready

public boolean ready()
See Also:
Reader.ready()

fillFully

public void fillFully(int length)
               throws java.io.IOException
Fill the buffer (blocking) up to the requested length.

Parameters:
length -
Throws:
java.io.IOException

availableChar

public int availableChar()

mark

public void mark(int readAheadLimit)

Supported with binary and character data.

See Also:
InputStream.mark(int), Reader.mark(int)

markSupported

public boolean markSupported()

Only supported with binary data.

See Also:
InputStream.markSupported()

reset

public void reset()
           throws java.io.IOException

Only supported with binary data.

Throws:
java.io.IOException
See Also:
InputStream.reset()

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException
See Also:
Closeable.close()

skip

public long skip(long n,
                 boolean block)
          throws java.io.IOException
Skips the specified number of bytes/characters.

Throws:
java.lang.IllegalStateException - if the stream that is using this InputBuffer is configured for asynchronous communication and the number of bytes/characters being skipped exceeds the number of bytes available in the buffer.
java.io.IOException
See Also:
InputStream.skip(long), Reader.skip(long)

finished

public void finished()
              throws java.io.IOException
When invoked, this method will call ReadHandler.onAllDataRead() on the current ReadHandler (if any). This method shouldn't be invoked by developers directly.

Throws:
java.io.IOException

isFinished

public boolean isFinished()
Returns:
true if all request data has been read, otherwise returns false.

isClosed

public boolean isClosed()
Returns:
true if this InputBuffer is closed, otherwise returns false.

notifyAvailable

public void notifyAvailable(ReadHandler handler)
Installs a ReadHandler that will be notified when any data becomes available to read without blocking.

Parameters:
handler - the ReadHandler to invoke.
Throws:
java.lang.IllegalArgumentException - if handler is null, or if size is less than zero.
java.lang.IllegalStateException - if an attempt is made to register a handler before an existing registered handler has been invoked or if all request data has already been read.

notifyAvailable

public void notifyAvailable(ReadHandler handler,
                            int size)
Installs a ReadHandler that will be notified when the specified amount of data is available to be read without blocking.

Parameters:
handler - the ReadHandler to invoke.
size - the minimum number of bytes that must be available before the ReadHandler is notified.
Throws:
java.lang.IllegalArgumentException - if handler is null, or if size is less than zero.
java.lang.IllegalStateException - if an attempt is made to register a handler before an existing registered handler has been invoked.

append

public boolean append(Buffer buffer)
               throws java.io.IOException
Appends the specified Buffer to the internal composite Buffer.

Parameters:
buffer - the Buffer to append
Returns:
true if ReadHandler.onDataAvailable() callback was invoked, otherwise returns false.
Throws:
java.io.IOException - if an error occurs appending the Buffer

isAsyncEnabled

public boolean isAsyncEnabled()
Returns:
if this buffer is being used to process asynchronous data.

setAsyncEnabled

public void setAsyncEnabled(boolean asyncEnabled)
Sets the asynchronous processing state of this InputBuffer.

Parameters:
asyncEnabled - true if this InputBuffer is to be used to process asynchronous request data.

terminate

public void terminate()

Invoke ReadHandler.onError(Throwable) (assuming a ReadHandler is available) } passing a {#link CancellationException} if the current Connection is open, or a {#link EOFException} if the connection was unexpectedly closed.

Since:
2.0.1


Copyright © 2011 Oracle Corpration. All Rights Reserved.