Package org.apache.catalina.connector
Class OutputBuffer
- java.lang.Object
- 
- java.io.Writer
- 
- org.apache.catalina.connector.OutputBuffer
 
 
- 
- All Implemented Interfaces:
- java.io.Closeable,- java.io.Flushable,- java.lang.Appendable,- java.lang.AutoCloseable
 
 public class OutputBuffer extends java.io.WriterThe 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 SummaryFields Modifier and Type Field Description protected C2BConverterconvCurrent char to byte converter.static intDEFAULT_BUFFER_SIZE
 - 
Constructor SummaryConstructors Constructor Description OutputBuffer()Default constructor.OutputBuffer(int size)Create the buffer with the specified initial size.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Deprecated 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(java.nio.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(java.nio.ByteBuffer buf)Sends the buffer data to the client output, checking the state of Response and calling the right interceptors.voidrealWriteChars(java.nio.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)voidsetEncoding(java.lang.String s)Deprecated.This method will be removed in Tomcat 9.0.xvoidsetResponse(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(java.lang.String s)voidwrite(java.lang.String s, int off, int len)Append a string to the buffervoidwrite(java.nio.ByteBuffer from)voidwriteByte(int b)
 
- 
- 
- 
Field Detail- 
DEFAULT_BUFFER_SIZEpublic static final int DEFAULT_BUFFER_SIZE - See Also:
- Constant Field Values
 
 - 
convprotected C2BConverter conv Current char to byte converter.
 
- 
 - 
Method Detail- 
setResponsepublic void setResponse(Response coyoteResponse) Associated Coyote response.- Parameters:
- coyoteResponse- Associated Coyote response
 
 - 
isSuspendedpublic boolean isSuspended() Is the response output suspended ?- Returns:
- suspended flag value
 
 - 
setSuspendedpublic void setSuspended(boolean suspended) Set the suspended flag.- Parameters:
- suspended- New suspended flag value
 
 - 
isClosedpublic boolean isClosed() Is the response output closed ?- Returns:
- closed flag value
 
 - 
recyclepublic void recycle() Recycle the output buffer.
 - 
closepublic void close() throws java.io.IOExceptionClose the output buffer. This tries to calculate the response size if the response has not been committed yet.- Specified by:
- closein interface- java.lang.AutoCloseable
- Specified by:
- closein interface- java.io.Closeable
- Specified by:
- closein class- java.io.Writer
- Throws:
- java.io.IOException- An underlying IOException occurred
 
 - 
flushpublic void flush() throws java.io.IOExceptionFlush bytes or chars contained in the buffer.- Specified by:
- flushin interface- java.io.Flushable
- Specified by:
- flushin class- java.io.Writer
- Throws:
- java.io.IOException- An underlying IOException occurred
 
 - 
doFlushprotected void doFlush(boolean realFlush) throws java.io.IOExceptionFlush bytes or chars contained in the buffer.- Parameters:
- realFlush-- trueif this should also cause a real network flush
- Throws:
- java.io.IOException- An underlying IOException occurred
 
 - 
realWriteBytespublic void realWriteBytes(java.nio.ByteBuffer buf) throws java.io.IOExceptionSends 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:
- java.io.IOException- An underlying IOException occurred
 
 - 
writepublic void write(byte[] b, int off, int len) throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
writepublic void write(java.nio.ByteBuffer from) throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
writeBytepublic void writeByte(int b) throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
realWriteCharspublic void realWriteChars(java.nio.CharBuffer from) throws java.io.IOExceptionConvert the chars to bytes, then send the data to the client.- Parameters:
- from- Char buffer to be written to the response
- Throws:
- java.io.IOException- An underlying IOException occurred
 
 - 
writepublic void write(int c) throws java.io.IOException- Overrides:
- writein class- java.io.Writer
- Throws:
- java.io.IOException
 
 - 
writepublic void write(char[] c) throws java.io.IOException- Overrides:
- writein class- java.io.Writer
- Throws:
- java.io.IOException
 
 - 
writepublic void write(char[] c, int off, int len) throws java.io.IOException- Specified by:
- writein class- java.io.Writer
- Throws:
- java.io.IOException
 
 - 
writepublic void write(java.lang.String s, int off, int len) throws java.io.IOExceptionAppend a string to the buffer- Overrides:
- writein class- java.io.Writer
- Throws:
- java.io.IOException
 
 - 
writepublic void write(java.lang.String s) throws java.io.IOException- Overrides:
- writein class- java.io.Writer
- Throws:
- java.io.IOException
 
 - 
setEncoding@Deprecated public void setEncoding(java.lang.String s) Deprecated.This method will be removed in Tomcat 9.0.x- Parameters:
- s- New encoding value
 
 - 
checkConverterpublic void checkConverter() throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
getContentWrittenpublic long getContentWritten() 
 - 
isNewpublic 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()
 
 - 
setBufferSizepublic void setBufferSize(int size) 
 - 
resetpublic void reset() 
 - 
resetpublic void reset(boolean resetWriterStreamFlags) 
 - 
getBufferSizepublic int getBufferSize() 
 - 
isReadypublic boolean isReady() 
 - 
setWriteListenerpublic void setWriteListener(WriteListener listener) 
 - 
isBlockingpublic boolean isBlocking() 
 - 
checkRegisterForWritepublic void checkRegisterForWrite() 
 - 
appendpublic void append(byte[] src, int off, int len) throws java.io.IOExceptionAdd data to the buffer.- Parameters:
- src- Bytes array
- off- Offset
- len- Length
- Throws:
- java.io.IOException- Writing overflow data to the output channel failed
 
 - 
appendpublic void append(char[] src, int off, int len) throws java.io.IOExceptionAdd data to the buffer.- Parameters:
- src- Char array
- off- Offset
- len- Length
- Throws:
- java.io.IOException- Writing overflow data to the output channel failed
 
 - 
appendpublic void append(java.nio.ByteBuffer from) throws java.io.IOException- Throws:
- java.io.IOException
 
 
- 
 
-