Package org.apache.catalina.connector
Class OutputBuffer
java.lang.Object
java.io.Writer
org.apache.catalina.connector.OutputBuffer
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
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).
- Author:
- Costin Manolache, Remy Maucherat
-
Field Summary
Modifier and TypeFieldDescriptionprotected C2BConverter
Current char to byte converter.static final int
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
append
(byte[] src, int off, int len) Add data to the buffer.void
append
(char[] src, int off, int len) Add data to the buffer.void
append
(ByteBuffer from) void
void
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.int
long
boolean
boolean
isClosed()
Is the response output closed ?boolean
isNew()
Has this buffer been used at all?boolean
isReady()
boolean
Is the response output suspended ?void
realWriteBytes
(ByteBuffer buf) Sends the buffer data to the client output, checking the state of Response and calling the right interceptors.void
realWriteChars
(CharBuffer from) Convert the chars to bytes, then send the data to the client.void
recycle()
Recycle the output buffer.void
reset()
void
reset
(boolean resetWriterStreamFlags) void
setBufferSize
(int size) void
void
setResponse
(Response coyoteResponse) Associated Coyote response.void
setSuspended
(boolean suspended) Set the suspended flag.void
setWriteListener
(WriteListener listener) 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
void
Append a string to the buffervoid
write
(ByteBuffer from) void
writeByte
(int b) Methods inherited from class java.io.Writer
append, append, append, nullWriter
-
Field Details
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE- See Also:
-
conv
Current char to byte converter.
-
-
Constructor Details
-
OutputBuffer
public OutputBuffer(int size) Create the buffer with the specified initial size.- Parameters:
size
- Buffer size to use
-
-
Method Details
-
setResponse
Associated Coyote response.- Parameters:
coyoteResponse
- 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
-
isClosed
public boolean isClosed()Is the response output closed ?- Returns:
- closed flag value
-
recycle
public void recycle()Recycle the output buffer. -
close
Close the output buffer. This tries to calculate the response size if the response has not been committed yet.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classWriter
- Throws:
IOException
- An underlying IOException occurred
-
flush
Flush bytes or chars contained in the buffer.- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in classWriter
- Throws:
IOException
- An underlying IOException occurred
-
doFlush
Flush bytes or chars contained in the buffer.- Parameters:
realFlush
-true
if this should also cause a real network flush- Throws:
IOException
- An underlying IOException occurred
-
realWriteBytes
Sends the buffer data to the client output, checking the state of Response and calling the right interceptors.- Parameters:
buf
- the ByteBuffer to be written to the response- Throws:
IOException
- An underlying IOException occurred
-
write
- Throws:
IOException
-
write
- Throws:
IOException
-
writeByte
- Throws:
IOException
-
realWriteChars
Convert the chars to bytes, then send the data to the client.- Parameters:
from
- Char buffer to be written to the response- Throws:
IOException
- An underlying IOException occurred
-
write
- Overrides:
write
in classWriter
- Throws:
IOException
-
write
- Overrides:
write
in classWriter
- Throws:
IOException
-
write
- Specified by:
write
in classWriter
- Throws:
IOException
-
write
Append a string to the buffer- Overrides:
write
in classWriter
- Throws:
IOException
-
write
- Overrides:
write
in classWriter
- Throws:
IOException
-
checkConverter
- Throws:
IOException
-
getContentWritten
public long getContentWritten() -
isNew
public boolean isNew()Has this buffer been used at all?- Returns:
- true if no chars or bytes have been added to the buffer since the last call to
recycle()
-
setBufferSize
public void setBufferSize(int size) -
reset
public void reset() -
reset
public void reset(boolean resetWriterStreamFlags) -
getBufferSize
public int getBufferSize() -
isReady
public boolean isReady() -
setWriteListener
-
isBlocking
public boolean isBlocking() -
checkRegisterForWrite
public void checkRegisterForWrite() -
append
Add data to the buffer.- Parameters:
src
- Bytes arrayoff
- Offsetlen
- Length- Throws:
IOException
- Writing overflow data to the output channel failed
-
append
Add data to the buffer.- Parameters:
src
- Char arrayoff
- Offsetlen
- Length- Throws:
IOException
- Writing overflow data to the output channel failed
-
append
- Throws:
IOException
-
setErrorException
-