org.apache.catalina.connector

Class OutputBuffer

public class OutputBuffer extends Writer implements ByteChunk.ByteOutputChannel

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
protected C2BConverterconv
Current char to byte converter.
static intDEFAULT_BUFFER_SIZE
static StringDEFAULT_ENCODING
protected HashMapencoders
List of encoders.
Constructor Summary
OutputBuffer()
Default constructor.
OutputBuffer(int size)
Alternate constructor which allows specifying the initial buffer size.
Method Summary
voidcheckConverter()
voidclearEncoders()
Clear cached encoders (to save memory for Comet requests).
voidclose()
Close the output buffer.
protected voiddoFlush(boolean realFlush)
Flush bytes or chars contained in the buffer.
voidflush()
Flush bytes or chars contained in the buffer.
voidflushBytes()
Real write - this buffer will be sent to the client
intgetBufferSize()
intgetBytesWritten()
intgetCharsWritten()
intgetContentWritten()
longgetContentWrittenLong()
ResponsegetResponse()
Get associated Coyote response.
booleanisClosed()
Is the response output closed ?
booleanisNew()
True if this buffer hasn't been used ( since recycle() ) - i.e. no chars or bytes have been added to the buffer.
booleanisSuspended()
Is the response output suspended ?
voidrealWriteBytes(byte[] buf, int off, int cnt)
Sends the buffer data to the client output, checking the state of Response and calling the right interceptors.
voidrecycle()
Recycle the output buffer.
voidreset()
voidsetBufferSize(int size)
protected voidsetConverter()
voidsetEncoding(String s)
voidsetResponse(Response coyoteResponse)
Associated Coyote response.
voidsetSuspended(boolean suspended)
Set the suspended flag.
voidwrite(byte[] b, int off, int len)
voidwrite(int c)
voidwrite(char[] c)
voidwrite(char[] c, int off, int len)
voidwrite(String s, int off, int len)
Append a string to the buffer
voidwrite(String s)
voidwriteByte(int b)

Field Detail

conv

protected C2BConverter conv
Current char to byte converter.

DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE

DEFAULT_ENCODING

public static final String DEFAULT_ENCODING

encoders

protected HashMap encoders
List of encoders.

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

checkConverter

public void checkConverter()

clearEncoders

public void clearEncoders()
Clear cached encoders (to save memory for Comet requests).

close

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

Throws: IOException An underlying IOException occurred

doFlush

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

Throws: IOException An underlying IOException occurred

flush

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

Throws: IOException An underlying IOException occurred

flushBytes

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

getBufferSize

public int getBufferSize()

getBytesWritten

public int getBytesWritten()

getCharsWritten

public int getCharsWritten()

getContentWritten

public int getContentWritten()

getContentWrittenLong

public long getContentWrittenLong()

getResponse

public Response getResponse()
Get associated Coyote response.

Returns: the associated Coyote response

isClosed

public boolean isClosed()
Is the response output closed ?

Returns: closed flag value

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

realWriteBytes

public 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.

Parameters: buf Byte buffer to be written to the response off Offset cnt Length

Throws: IOException An underlying IOException occurred

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(byte[] b, int off, int len)

write

public void write(int c)

write

public void write(char[] c)

write

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

write

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

write

public void write(String s)

writeByte

public void writeByte(int b)
Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.