org.apache.coyote.tomcat4

Class OutputBuffer

Implemented Interfaces:
ByteChunk.ByteOutputChannel, CharChunk.CharOutputChannel

public class OutputBuffer
extends Writer
implements ByteChunk.ByteOutputChannel, 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).

Authors:
Costin Manolache
Remy Maucherat

Field Summary

int
BYTE_STATE
int
CHAR_STATE
static int
DEFAULT_BUFFER_SIZE
static String
DEFAULT_ENCODING
int
INITIAL_STATE
protected C2BConverter
conv
Current char to byte converter.
protected Hashtable
encoders
List of encoders.

Constructor Summary

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

Method Summary

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()
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 ?
protected void
log(String s)
void
realWriteBytes(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(c[] , int off, int len)
void
recycle()
Recycle the output buffer.
void
reset()
void
setBufferSize(int size)
protected void
setConverter()
void
setEncoding(String s)
void
setResponse(Response coyoteResponse)
Associated Coyote response.
void
setSuspended(boolean suspended)
Set the suspended flag.
void
write(String s)
void
write(String s, int off, int len)
Append a string to the buffer
void
write(StringBuffer sb)
void
write(b[] , int off, int len)
void
write(c[] )
void
write(c[] , int off, int len)
void
write(int c)
void
writeByte(int b)

Field Details

BYTE_STATE

public final int BYTE_STATE


CHAR_STATE

public final int CHAR_STATE


DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE

Field Value:
8192


DEFAULT_ENCODING

public static final String DEFAULT_ENCODING


INITIAL_STATE

public final int INITIAL_STATE


conv

protected C2BConverter conv
Current char to byte converter.


encoders

protected Hashtable encoders
List of encoders.

Constructor Details

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 Details

close

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


doFlush

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


flush

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


flushBytes

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


flushChars

public void flushChars()
            throws IOException


flushCharsNeeded

public boolean flushCharsNeeded()


getBufferSize

public int getBufferSize()


getBytesWritten

public int getBytesWritten()


getCharsWritten

public int getCharsWritten()


getContentWritten

public int getContentWritten()


getResponse

public Response getResponse()
Get associated Coyote response.

Returns:
the associated Coyote response


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.


isSuspended

public boolean isSuspended()
Is the response output suspended ?

Returns:
suspended flag value


log

protected void log(String s)


realWriteBytes

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

Parameters:
off - Offset
cnt - Length


realWriteChars

public void realWriteChars(c[] ,
                           int off,
                           int len)
            throws IOException


recycle

public void recycle()
Recycle the output buffer.


reset

public void reset()


setBufferSize

public void setBufferSize(int size)


setConverter

protected void setConverter()


setEncoding

public void setEncoding(String s)


setResponse

public void setResponse(Response coyoteResponse)
Associated Coyote response.

Parameters:
coyoteResponse - Associated Coyote response


setSuspended

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

Parameters:
suspended - New suspended flag value


write

public void write(String s)
            throws IOException


write

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


write

public void write(StringBuffer sb)
            throws IOException


write

public void write(b[] ,
                  int off,
                  int len)
            throws IOException


write

public void write(c[] )
            throws IOException


write

public void write(c[] ,
                  int off,
                  int len)
            throws IOException


write

public void write(int c)
            throws IOException


writeByte

public void writeByte(int b)
            throws IOException


Copyright B) 2000-2003 Apache Software Foundation. All Rights Reserved.