Top Description Inners Fields Constructors Methods
org.apache.catalina.connector

public Class OutputBuffer

extends Writer
Class Inheritance
Imports
java.io.IOException, .Writer, java.nio.Buffer, .ByteBuffer, .CharBuffer, java.nio.charset.Charset, java.security.AccessController, .PrivilegedActionException, .PrivilegedExceptionAction, java.util.HashMap, .Map, jakarta.servlet.WriteListener, jakarta.servlet.http.HttpServletResponse, org.apache.catalina.Globals, org.apache.coyote.ActionCode, .CloseNowException, .Response, org.apache.tomcat.util.buf.B2CConverter, .C2BConverter, org.apache.tomcat.util.res.StringManager

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 responsibility).
Authors
Costin Manolache, Remy Maucherat

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private ByteBuffer
bb

The byte buffer.

private long
bytesWritten

Number of bytes written.

private final CharBuffer
cb

The char buffer.

private long
charsWritten

Number of chars written.

private volatile boolean
closed

Flag which indicates if the output buffer is closed.

protected C2BConverter
conv

Current char to byte converter.

private Response
coyoteResponse

Associated Coyote response.

public static final int
private final int
defaultBufferSize

Default buffer size.

private boolean
doFlush

Do a flush on the next operation.

private final Map<Charset, C2BConverter>
encoders

Encoder cache.

private boolean
initial

State of the output buffer.

private static final StringManager
private volatile boolean
suspended

Suspended flag.

Inherited from java.io.Writer:
lock

Constructor Summary

AccessConstructor and Description
public
OutputBuffer(int
Buffer size to use
size
)

Create the buffer with the specified initial size.

Method Summary

Modifier and TypeMethod and Description
public void
append(byte[]
Bytes array
src
,
int
Offset
off
,
int
Length
len
)

Add data to the buffer.

public void
append(char[]
Char array
src
,
int
Offset
off
,
int
Length
len
)

Add data to the buffer.

public void
private void
appendByteArray(byte[] src, int off, int len)

private void
public void
public void
private void
clear(Buffer buffer)

public void
close()

Implements abstract java.io.Writer.close.

Implements java.io.Closeable.close.

Close the output buffer.

private static C2BConverter
createConverter(final Charset charset)

protected void
doFlush(boolean
true if this should also cause a real network flush
realFlush
)

Flush bytes or chars contained in the buffer.

public void
flush()

Implements abstract java.io.Writer.flush.

Implements java.io.Flushable.flush.

Flush bytes or chars contained in the buffer.

private void
private void
public int
public long
public boolean
public boolean

Returns:

closed flag value
isClosed
()

Is the response output closed ?

private boolean
isFull(Buffer buffer)

public boolean

Returns:

true if no chars or bytes have been added to the buffer since the last call to recycle()
isNew
()

Has this buffer been used at all?

public boolean
public boolean

Returns:

suspended flag value
isSuspended
()

Is the response output suspended ?

public void
realWriteBytes(ByteBuffer
the ByteBuffer to be written to the response
buf
)

Sends the buffer data to the client output, checking the state of Response and calling the right interceptors.

public void
realWriteChars(CharBuffer
Char buffer to be written to the response
from
)

Convert the chars to bytes, then send the data to the client.

public void
recycle()

Recycle the output buffer.

public void
public void
reset(boolean resetWriterStreamFlags)

public void
setBufferSize(int size)

public void
setResponse(Response
Associated Coyote response
coyoteResponse
)

Associated Coyote response.

public void
setSuspended(boolean
New suspended flag value
suspended
)

Set the suspended flag.

public void
private void
private void
private void
transfer(byte b, ByteBuffer to)

private void
transfer(char b, CharBuffer to)

private int
transfer(byte[] buf, int off, int len, ByteBuffer to)

private int
transfer(char[] buf, int off, int len, CharBuffer to)

private int
transfer(String s, int off, int len, CharBuffer to)

private void
public void
write(byte[] b, int off, int len)

public void
public void
write(int
int specifying a character to be written
c
)

Overrides java.io.Writer.write.

Writes a single character.

public void
write(char[]
Array of characters to be written
c
)

Overrides java.io.Writer.write.

Writes an array of characters.

public void
write(char[]
Array of characters
c
,
int
Offset from which to start writing characters
off
,
int
Number of characters to write
len
)

Implements abstract java.io.Writer.write.

Writes a portion of an array of characters.

public void
write(String
A String
s
,
int
Offset from which to start writing characters
off
,
int
Number of characters to write
len
)

Overrides java.io.Writer.write.

Append a string to the buffer

public void
write(String
String to be written
s
)

Overrides java.io.Writer.write.

Writes a string.

public void
writeByte(int b)

private void
writeBytes(byte[] b, int off, int len)

private void
Inherited from java.io.Writer:
appendappendappendnullWriter

Field Detail

bbback to summary
private ByteBuffer bb

The byte buffer.

bytesWrittenback to summary
private long bytesWritten

Number of bytes written.

cbback to summary
private final CharBuffer cb

The char buffer.

charsWrittenback to summary
private long charsWritten

Number of chars written.

closedback to summary
private volatile boolean closed

Flag which indicates if the output buffer is closed.

convback to summary
protected C2BConverter conv

Current char to byte converter.

coyoteResponseback to summary
private Response coyoteResponse

Associated Coyote response.

DEFAULT_BUFFER_SIZEback to summary
public static final int DEFAULT_BUFFER_SIZE
defaultBufferSizeback to summary
private final int defaultBufferSize

Default buffer size.

doFlushback to summary
private boolean doFlush

Do a flush on the next operation.

encodersback to summary
private final Map<Charset, C2BConverter> encoders

Encoder cache.

initialback to summary
private boolean initial

State of the output buffer.

smback to summary
private static final StringManager sm
suspendedback to summary
private volatile boolean suspended

Suspended flag. All output bytes will be swallowed if this is true.

Constructor Detail

OutputBufferback to summary
public OutputBuffer(int size)

Create the buffer with the specified initial size.

Parameters
size:int

Buffer size to use

Method Detail

appendback to summary
public void append(byte[] src, int off, int len) throws IOException

Add data to the buffer.

Parameters
src:byte[]

Bytes array

off:int

Offset

len:int

Length

Exceptions
IOException:
Writing overflow data to the output channel failed
appendback to summary
public void append(char[] src, int off, int len) throws IOException

Add data to the buffer.

Parameters
src:char[]

Char array

off:int

Offset

len:int

Length

Exceptions
IOException:
Writing overflow data to the output channel failed
appendback to summary
public void append(ByteBuffer from) throws IOException
appendByteArrayback to summary
private void appendByteArray(byte[] src, int off, int len) throws IOException
appendByteBufferback to summary
private void appendByteBuffer(ByteBuffer from) throws IOException
checkConverterback to summary
public void checkConverter() throws IOException
checkRegisterForWriteback to summary
public void checkRegisterForWrite()
clearback to summary
private void clear(Buffer buffer)
closeback to summary
public void close() throws IOException

Implements abstract java.io.Writer.close.

Implements java.io.Closeable.close.

Close the output buffer. This tries to calculate the response size if the response has not been committed yet.

Annotations
@Override
Exceptions
IOException:
An underlying IOException occurred
createConverterback to summary
private static C2BConverter createConverter(final Charset charset) throws IOException
doFlushback to summary
protected void doFlush(boolean realFlush) throws IOException

Flush bytes or chars contained in the buffer.

Parameters
realFlush:boolean

true if this should also cause a real network flush

Exceptions
IOException:
An underlying IOException occurred
flushback to summary
public void flush() throws IOException

Implements abstract java.io.Writer.flush.

Implements java.io.Flushable.flush.

Flush bytes or chars contained in the buffer.

Annotations
@Override
Exceptions
IOException:
An underlying IOException occurred
flushByteBufferback to summary
private void flushByteBuffer() throws IOException
flushCharBufferback to summary
private void flushCharBuffer() throws IOException
getBufferSizeback to summary
public int getBufferSize()
getContentWrittenback to summary
public long getContentWritten()
isBlockingback to summary
public boolean isBlocking()
isClosedback to summary
public boolean isClosed()

Is the response output closed ?

Returns:boolean

closed flag value

isFullback to summary
private boolean isFull(Buffer buffer)
isNewback to summary
public boolean isNew()

Has this buffer been used at all?

Returns:boolean

true if no chars or bytes have been added to the buffer since the last call to recycle()

isReadyback to summary
public boolean isReady()
isSuspendedback to summary
public boolean isSuspended()

Is the response output suspended ?

Returns:boolean

suspended flag value

realWriteBytesback to summary
public void realWriteBytes(ByteBuffer buf) throws IOException

Sends the buffer data to the client output, checking the state of Response and calling the right interceptors.

Parameters
buf:ByteBuffer

the ByteBuffer to be written to the response

Exceptions
IOException:
An underlying IOException occurred
realWriteCharsback to summary
public void realWriteChars(CharBuffer from) throws IOException

Convert the chars to bytes, then send the data to the client.

Parameters
from:CharBuffer

Char buffer to be written to the response

Exceptions
IOException:
An underlying IOException occurred
recycleback to summary
public void recycle()

Recycle the output buffer.

resetback to summary
public void reset()
resetback to summary
public void reset(boolean resetWriterStreamFlags)
setBufferSizeback to summary
public void setBufferSize(int size)
setResponseback to summary
public void setResponse(Response coyoteResponse)

Associated Coyote response.

Parameters
coyoteResponse:Response

Associated Coyote response

setSuspendedback to summary
public void setSuspended(boolean suspended)

Set the suspended flag.

Parameters
suspended:boolean

New suspended flag value

setWriteListenerback to summary
public void setWriteListener(WriteListener listener)
toReadModeback to summary
private void toReadMode(Buffer buffer)
toWriteModeback to summary
private void toWriteMode(Buffer buffer)
transferback to summary
private void transfer(byte b, ByteBuffer to)
transferback to summary
private void transfer(char b, CharBuffer to)
transferback to summary
private int transfer(byte[] buf, int off, int len, ByteBuffer to)
transferback to summary
private int transfer(char[] buf, int off, int len, CharBuffer to)
transferback to summary
private int transfer(String s, int off, int len, CharBuffer to)
transferback to summary
private void transfer(ByteBuffer from, ByteBuffer to)
writeback to summary
public void write(byte[] b, int off, int len) throws IOException
writeback to summary
public void write(ByteBuffer from) throws IOException
writeback to summary
public void write(int c) throws IOException

Overrides java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a single character. The character to be written is contained in the 16 low-order bits of the given integer value; the 16 high-order bits are ignored.

Subclasses that intend to support efficient single-character output should override this method.

Parameters
c:int

int specifying a character to be written

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(char[] c) throws IOException

Overrides java.io.Writer.write.

Doc from java.io.Writer.write.

Writes an array of characters.

Parameters
c:char[]

Array of characters to be written

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(char[] c, int off, int len) throws IOException

Implements abstract java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a portion of an array of characters.

Parameters
c:char[]

Array of characters

off:int

Offset from which to start writing characters

len:int

Number of characters to write

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(String s, int off, int len) throws IOException

Overrides java.io.Writer.write.

Append a string to the buffer

Parameters
s:String

Doc from java.io.Writer.write.

A String

off:int

Doc from java.io.Writer.write.

Offset from which to start writing characters

len:int

Doc from java.io.Writer.write.

Number of characters to write

Annotations
@Override
Exceptions
IOException:

Doc from java.io.Writer.write.

If an I/O error occurs

writeback to summary
public void write(String s) throws IOException

Overrides java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a string.

Parameters
s:String

String to be written

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
writeByteback to summary
public void writeByte(int b) throws IOException
writeBytesback to summary
private void writeBytes(byte[] b, int off, int len) throws IOException
writeBytesback to summary
private void writeBytes(ByteBuffer from) throws IOException
org.apache.catalina.connector back to summary

private Class OutputBuffer.PrivilegedCreateConverter

extends Object
implements PrivilegedExceptionAction<C2BConverter>
Class Inheritance
  • java.lang.Object
  • org.apache.catalina.connector.OutputBuffer.PrivilegedCreateConverter
All Implemented Interfaces
java.security.PrivilegedExceptionAction

Field Summary

Modifier and TypeField and Description
private final Charset

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public C2BConverter
run()

Implements java.security.PrivilegedExceptionAction.run.

Performs the computation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

charsetback to summary
private final Charset charset

Constructor Detail

PrivilegedCreateConverterback to summary
pack-priv PrivilegedCreateConverter(Charset charset)

Method Detail

runback to summary
public C2BConverter run() throws IOException

Implements java.security.PrivilegedExceptionAction.run.

Doc from java.security.PrivilegedExceptionAction.run.

Performs the computation. This method will be called by AccessController.doPrivileged after enabling privileges.

Returns:C2BConverter

a class-dependent value that may represent the results of the computation. Each class that implements PrivilegedExceptionAction should document what (if anything) this value represents.

Annotations
@Override