org.jboss.remoting.transport.coyote
Class OutputBuffer

java.lang.Object
  extended by java.io.Writer
      extended by org.jboss.remoting.transport.coyote.OutputBuffer
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, java.lang.Appendable, org.apache.tomcat.util.buf.ByteChunk.ByteOutputChannel, org.apache.tomcat.util.buf.CharChunk.CharOutputChannel

public class OutputBuffer
extends java.io.Writer
implements org.apache.tomcat.util.buf.ByteChunk.ByteOutputChannel, org.apache.tomcat.util.buf.CharChunk.CharOutputChannel

The buffer used by Tomcat response. This is a derivative of the Tomcat 3.3 OutputBuffer, with the removal of some of the state handling (which in Coyote is mostly the Processor's responsability).

Author:
Costin Manolache, Remy Maucherat

Field Summary
 int BYTE_STATE
           
 int CHAR_STATE
           
protected  org.apache.tomcat.util.buf.C2BConverter conv
          Current char to byte converter.
static int DEFAULT_BUFFER_SIZE
           
static java.lang.String DEFAULT_ENCODING
           
protected  java.util.HashMap encoders
          List of encoders.
 int INITIAL_STATE
           
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
OutputBuffer()
          Default constructor.
OutputBuffer(int size)
          Alternate constructor which allows specifying the initial buffer size.
 
Method Summary
 void checkConverter()
           
 void close()
          Close the output buffer.
protected  void doFlush(boolean realFlush)
          Flush bytes or chars contained in the buffer.
 void flush()
          Flush bytes or chars contained in the buffer.
 void flushBytes()
          Real write - this buffer will be sent to the client
 void flushChars()
           
 boolean flushCharsNeeded()
           
 int getBufferSize()
           
 int getBytesWritten()
           
 int getCharsWritten()
           
 int getContentWritten()
           
 org.apache.coyote.Response getResponse()
          Get associated Coyote response.
 boolean isNew()
          True if this buffer hasn't been used ( since recycle() ) - i.e.
 boolean isSuspended()
          Is the response output suspended ?
 void realWriteBytes(byte[] buf, int off, int cnt)
          Sends the buffer data to the client output, checking the state of Response and calling the right interceptors.
 void realWriteChars(char[] c, int off, int len)
           
 void recycle()
          Recycle the output buffer.
 void reset()
           
 void setBufferSize(int size)
           
protected  void setConverter()
           
 void setEncoding(java.lang.String s)
           
 void setResponse(org.apache.coyote.Response coyoteResponse)
          Associated Coyote response.
 void setSuspended(boolean suspended)
          Set the suspended flag.
 void write(byte[] b, int off, int len)
           
 void write(char[] c)
           
 void write(char[] c, int off, int len)
           
 void write(int c)
           
 void write(java.lang.String s)
           
 void write(java.lang.StringBuffer sb)
           
 void write(java.lang.String s, int off, int len)
          Append a string to the buffer
 void writeByte(int b)
           
 
Methods inherited from class java.io.Writer
append, append, append
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ENCODING

public static final java.lang.String DEFAULT_ENCODING
See Also:
Constant Field Values

DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE
See Also:
Constant Field Values

INITIAL_STATE

public final int INITIAL_STATE
See Also:
Constant Field Values

CHAR_STATE

public final int CHAR_STATE
See Also:
Constant Field Values

BYTE_STATE

public final int BYTE_STATE
See Also:
Constant Field Values

encoders

protected java.util.HashMap encoders
List of encoders.


conv

protected org.apache.tomcat.util.buf.C2BConverter conv
Current char to byte converter.

Constructor Detail

OutputBuffer

public OutputBuffer()
Default constructor. Allocate the buffer with the default buffer size.


OutputBuffer

public OutputBuffer(int size)
Alternate constructor which allows specifying the initial buffer size.

Parameters:
size - Buffer size to use
Method Detail

setResponse

public void setResponse(org.apache.coyote.Response coyoteResponse)
Associated Coyote response.

Parameters:
coyoteResponse - Associated Coyote response

getResponse

public org.apache.coyote.Response getResponse()
Get associated Coyote response.

Returns:
the associated Coyote response

isSuspended

public boolean isSuspended()
Is the response output suspended ?

Returns:
suspended flag value

setSuspended

public void setSuspended(boolean suspended)
Set the suspended flag.

Parameters:
suspended - New suspended flag value

recycle

public void recycle()
Recycle the output buffer.


close

public void close()
           throws java.io.IOException
Close the output buffer. This tries to calculate the response size if the response has not been committed yet.

Specified by:
close in interface java.io.Closeable
Specified by:
close in class java.io.Writer
Throws:
java.io.IOException - An underlying IOException occurred

flush

public void flush()
           throws java.io.IOException
Flush bytes or chars contained in the buffer.

Specified by:
flush in interface java.io.Flushable
Specified by:
flush in class java.io.Writer
Throws:
java.io.IOException - An underlying IOException occurred

doFlush

protected void doFlush(boolean realFlush)
                throws java.io.IOException
Flush bytes or chars contained in the buffer.

Throws:
java.io.IOException - An underlying IOException occurred

realWriteBytes

public void realWriteBytes(byte[] buf,
                           int off,
                           int cnt)
                    throws java.io.IOException
Sends the buffer data to the client output, checking the state of Response and calling the right interceptors.

Specified by:
realWriteBytes in interface org.apache.tomcat.util.buf.ByteChunk.ByteOutputChannel
Parameters:
buf - Byte buffer to be written to the response
off - Offset
cnt - Length
Throws:
java.io.IOException - An underlying IOException occurred

write

public void write(byte[] b,
                  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(int c)
           throws java.io.IOException
Overrides:
write in class java.io.Writer
Throws:
java.io.IOException

write

public void write(char[] c)
           throws java.io.IOException
Overrides:
write in class java.io.Writer
Throws:
java.io.IOException

write

public void write(char[] c,
                  int off,
                  int len)
           throws java.io.IOException
Specified by:
write in class java.io.Writer
Throws:
java.io.IOException

write

public void write(java.lang.StringBuffer sb)
           throws java.io.IOException
Throws:
java.io.IOException

write

public void write(java.lang.String s,
                  int off,
                  int len)
           throws java.io.IOException
Append a string to the buffer

Overrides:
write in class java.io.Writer
Throws:
java.io.IOException

write

public void write(java.lang.String s)
           throws java.io.IOException
Overrides:
write in class java.io.Writer
Throws:
java.io.IOException

flushChars

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

flushCharsNeeded

public boolean flushCharsNeeded()

setEncoding

public void setEncoding(java.lang.String s)

realWriteChars

public void realWriteChars(char[] c,
                           int off,
                           int len)
                    throws java.io.IOException
Specified by:
realWriteChars in interface org.apache.tomcat.util.buf.CharChunk.CharOutputChannel
Throws:
java.io.IOException

checkConverter

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

setConverter

protected void setConverter()
                     throws java.io.IOException
Throws:
java.io.IOException

flushBytes

public void flushBytes()
                throws java.io.IOException
Real write - this buffer will be sent to the client

Throws:
java.io.IOException

getBytesWritten

public int getBytesWritten()

getCharsWritten

public int getCharsWritten()

getContentWritten

public int getContentWritten()

isNew

public boolean isNew()
True if this buffer hasn't been used ( since recycle() ) - i.e. no chars or bytes have been added to the buffer.


setBufferSize

public void setBufferSize(int size)

reset

public void reset()

getBufferSize

public int getBufferSize()


Copyright © 1998-2005 JBoss Inc . All Rights Reserved.