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

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

public class OutputBuffer
extends java.lang.Object

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


Nested Class Summary
static interface OutputBuffer.LifeCycleListener
           
 
Constructor Summary
OutputBuffer()
           
 
Method Summary
 void acknowledge()
          Acknowledge a HTTP Expect header.
 boolean canWrite(int length)
           
 boolean canWriteChar(int length)
           
 void close()
           
 void endRequest()
           
 void flush()
          Flush the response.
 int getBufferedDataSize()
          Get the number of bytes buffered on OutputBuffer and ready to be sent.
 int getBufferSize()
           
 void initialize(Response response, FilterChainContext ctx)
           
 boolean isAsyncEnabled()
           Returns true if content will be written in a non-blocking fashion, otherwise returns false.
 boolean isClosed()
           
 void notifyCanWrite(WriteHandler handler, int length)
           
 void prepareCharacterEncoder()
           
 void recycle()
          Recycle the output buffer.
 void registerLifeCycleListener(OutputBuffer.LifeCycleListener listener)
           
 boolean removeLifeCycleListener(OutputBuffer.LifeCycleListener listener)
           
 void reset()
          Reset current response.
 void setAsyncEnabled(boolean asyncEnabled)
          Sets the asynchronous processing state of this OutputBuffer.
 void setBufferSize(int bufferSize)
           
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void write(char[] cbuf)
           
 void write(char[] cbuf, int off, int len)
           
 void write(java.lang.String str)
           
 void write(java.lang.String str, int off, int len)
           
 void writeBuffer(Buffer buffer)
           Writes the contents of the specified Buffer to the client.
 void writeByte(int b)
           
 void writeByteBuffer(java.nio.ByteBuffer byteBuffer)
           Writes the contents of the specified ByteBuffer to the client.
 void writeChar(int c)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OutputBuffer

public OutputBuffer()
Method Detail

initialize

public void initialize(Response response,
                       FilterChainContext ctx)

isAsyncEnabled

public boolean isAsyncEnabled()

Returns true if content will be written in a non-blocking fashion, otherwise returns false.

Returns:
true if content will be written in a non-blocking fashion, otherwise returns false.
Since:
2.1.2

setAsyncEnabled

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

Parameters:
asyncEnabled - true if this OutputBuffer will write content without blocking.
Since:
2.1.2

prepareCharacterEncoder

public void prepareCharacterEncoder()

getBufferSize

public int getBufferSize()

registerLifeCycleListener

public void registerLifeCycleListener(OutputBuffer.LifeCycleListener listener)

removeLifeCycleListener

public boolean removeLifeCycleListener(OutputBuffer.LifeCycleListener listener)

setBufferSize

public void setBufferSize(int bufferSize)

reset

public void reset()
Reset current response.

Throws:
java.lang.IllegalStateException - if the response has already been committed

isClosed

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

getBufferedDataSize

public int getBufferedDataSize()
Get the number of bytes buffered on OutputBuffer and ready to be sent.

Returns:
the number of bytes buffered on OutputBuffer and ready to be sent.

recycle

public void recycle()
Recycle the output buffer. This should be called when closing the connection.


endRequest

public void endRequest()
                throws java.io.IOException
Throws:
java.io.IOException

acknowledge

public void acknowledge()
                 throws java.io.IOException
Acknowledge a HTTP Expect header. The response status code and reason phrase should be set before invoking this method.

Throws:
java.io.IOException - if an error occurs writing the acknowledgment.

write

public void write(char[] cbuf,
                  int off,
                  int len)
           throws java.io.IOException
Throws:
java.io.IOException

writeChar

public void writeChar(int c)
               throws java.io.IOException
Throws:
java.io.IOException

write

public void write(char[] cbuf)
           throws java.io.IOException
Throws:
java.io.IOException

write

public void write(java.lang.String str)
           throws java.io.IOException
Throws:
java.io.IOException

write

public void write(java.lang.String str,
                  int off,
                  int len)
           throws java.io.IOException
Throws:
java.io.IOException

writeByte

public void writeByte(int b)
               throws java.io.IOException
Throws:
java.io.IOException

write

public void write(byte[] b)
           throws java.io.IOException
Throws:
java.io.IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Throws:
java.io.IOException

close

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

flush

public void flush()
           throws java.io.IOException
Flush the response.

Throws:
java.io.IOException - an underlying I/O error occurred

writeByteBuffer

public void writeByteBuffer(java.nio.ByteBuffer byteBuffer)
                     throws java.io.IOException

Writes the contents of the specified ByteBuffer to the client.

Note, that passed ByteBuffer will be directly used by underlying connection, so it could be reused only if it has been flushed.

Parameters:
byteBuffer - the ByteBuffer to write
Throws:
java.io.IOException - if an error occurs during the write

writeBuffer

public void writeBuffer(Buffer buffer)
                 throws java.io.IOException

Writes the contents of the specified Buffer to the client.

Note, that passed Buffer will be directly used by underlying connection, so it could be reused only if it has been flushed.

Parameters:
buffer - the Buffer to write
Throws:
java.io.IOException - if an error occurs during the write

canWriteChar

public boolean canWriteChar(int length)

canWrite

public boolean canWrite(int length)
See Also:
AsyncQueueWriter.canWrite(org.glassfish.grizzly.Connection, int)

notifyCanWrite

public void notifyCanWrite(WriteHandler handler,
                           int length)


Copyright © 2011 Oracle Corpration. All Rights Reserved.