Class 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
    • Constructor Detail

      • OutputBuffer

        public OutputBuffer()
        Default constructor. Allocate the buffer with the default buffer size.
      • OutputBuffer

        public OutputBuffer​(int size)
        Create the buffer with the specified initial size.
        Parameters:
        size - Buffer size to use
    • 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 IOException
        Close the output buffer. This tries to calculate the response size if the response has not been committed yet.
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
        Specified by:
        close in class Writer
        Throws:
        IOException - An underlying IOException occurred
      • doFlush

        protected void doFlush​(boolean realFlush)
                        throws IOException
        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

        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
      • 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
      • setEncoding

        @Deprecated
        public void setEncoding​(String s)
        Deprecated.
        This method will be removed in Tomcat 9.0.x
        Parameters:
        s - New encoding value
      • 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 IOException
        Add data to the buffer.
        Parameters:
        src - Bytes array
        off - Offset
        len - Length
        Throws:
        IOException - Writing overflow data to the output channel failed
      • append

        public void append​(char[] src,
                           int off,
                           int len)
                    throws IOException
        Add data to the buffer.
        Parameters:
        src - Char array
        off - Offset
        len - Length
        Throws:
        IOException - Writing overflow data to the output channel failed