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
public class OutputBuffer extends Writer
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
Fields Modifier and Type Field Description protected C2BConverterconvCurrent char to byte converter.static intDEFAULT_BUFFER_SIZE
-
Constructor Summary
Constructors Constructor Description OutputBuffer(int size)Create the buffer with the specified initial size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappend(byte[] src, int off, int len)Add data to the buffer.voidappend(char[] src, int off, int len)Add data to the buffer.voidappend(ByteBuffer from)voidcheckConverter()voidcheckRegisterForWrite()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.intgetBufferSize()longgetContentWritten()booleanisBlocking()booleanisClosed()Is the response output closed ?booleanisNew()Has this buffer been used at all?booleanisReady()booleanisSuspended()Is the response output suspended ?voidrealWriteBytes(ByteBuffer buf)Sends the buffer data to the client output, checking the state of Response and calling the right interceptors.voidrealWriteChars(CharBuffer from)Convert the chars to bytes, then send the data to the client.voidrecycle()Recycle the output buffer.voidreset()voidreset(boolean resetWriterStreamFlags)voidsetBufferSize(int size)voidsetResponse(Response coyoteResponse)Associated Coyote response.voidsetSuspended(boolean suspended)Set the suspended flag.voidsetWriteListener(WriteListener listener)voidwrite(byte[] b, int off, int len)voidwrite(char[] c)voidwrite(char[] c, int off, int len)voidwrite(int c)voidwrite(String s)voidwrite(String s, int off, int len)Append a string to the buffervoidwrite(ByteBuffer from)voidwriteByte(int b)-
Methods inherited from class java.io.Writer
append, append, append, nullWriter
-
-
-
-
Field Detail
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE
- See Also:
- Constant Field Values
-
conv
protected C2BConverter conv
Current char to byte converter.
-
-
Method Detail
-
setResponse
public void setResponse(Response coyoteResponse)
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
public void close() throws IOExceptionClose the output buffer. This tries to calculate the response size if the response has not been committed yet.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException- An underlying IOException occurred
-
flush
public void flush() throws IOExceptionFlush bytes or chars contained in the buffer.- Specified by:
flushin interfaceFlushable- Specified by:
flushin classWriter- Throws:
IOException- An underlying IOException occurred
-
doFlush
protected void doFlush(boolean realFlush) throws IOExceptionFlush bytes or chars contained in the buffer.- Parameters:
realFlush-trueif this should also cause a real network flush- Throws:
IOException- An underlying IOException occurred
-
realWriteBytes
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- the ByteBuffer to be written to the response- Throws:
IOException- An underlying IOException occurred
-
write
public void write(byte[] b, int off, int len) throws IOException- Throws:
IOException
-
write
public void write(ByteBuffer from) throws IOException
- Throws:
IOException
-
writeByte
public void writeByte(int b) throws IOException- Throws:
IOException
-
realWriteChars
public void realWriteChars(CharBuffer from) throws IOException
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
public void write(int c) throws IOException- Overrides:
writein classWriter- Throws:
IOException
-
write
public void write(char[] c) throws IOException- Overrides:
writein classWriter- Throws:
IOException
-
write
public void write(char[] c, int off, int len) throws IOException- Specified by:
writein classWriter- Throws:
IOException
-
write
public void write(String s, int off, int len) throws IOException
Append a string to the buffer- Overrides:
writein classWriter- Throws:
IOException
-
write
public void write(String s) throws IOException
- Overrides:
writein classWriter- Throws:
IOException
-
checkConverter
public void checkConverter() throws IOException- 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
public void setWriteListener(WriteListener listener)
-
isBlocking
public boolean isBlocking()
-
checkRegisterForWrite
public void checkRegisterForWrite()
-
append
public void append(byte[] src, int off, int len) throws IOExceptionAdd data to the buffer.- Parameters:
src- Bytes arrayoff- Offsetlen- Length- Throws:
IOException- Writing overflow data to the output channel failed
-
append
public void append(char[] src, int off, int len) throws IOExceptionAdd data to the buffer.- Parameters:
src- Char arrayoff- Offsetlen- Length- Throws:
IOException- Writing overflow data to the output channel failed
-
append
public void append(ByteBuffer from) throws IOException
- Throws:
IOException
-
-