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
,org.glassfish.grizzly.http.util.ByteChunk.ByteOutputChannel
public class OutputBuffer extends Writer implements org.glassfish.grizzly.http.util.ByteChunk.ByteOutputChannel
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 static int
DEFAULT_BUFFER_SIZE
static String
DEFAULT_ENCODING
-
Constructor Summary
Constructors Constructor Description OutputBuffer()
Default constructor.OutputBuffer(int size)
Alternate constructor which allows specifying the initial buffer size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkConverter()
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.void
flushBytes()
Real write - this buffer will be sent to the clientint
getBufferSize()
int
getBytesWritten()
int
getCharsWritten()
int
getContentWritten()
boolean
hasData()
Are there any pending writes waiting to be flushed?boolean
isNew()
True if this buffer hasn't been used ( since recycle() ) - i.e.boolean
isReady()
boolean
isSuspended()
Is the response output suspended ?void
realWriteBytes(byte[] buf, int off, int cnt)
Sends the buffer data to the client output, checking the state of Response and calling the right interceptors.void
recycle()
Recycle the output buffer.void
reset()
void
setBufferSize(int size)
void
setCoyoteResponse(Response coyoteResponse)
void
setSuspended(boolean suspended)
Set the suspended flag.void
setWriteListener(jakarta.servlet.WriteListener writeListener)
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
write(String s)
void
write(String s, int off, int len)
Append a string to the buffervoid
writeByte(int b)
-
Methods inherited from class java.io.Writer
append, append, append, nullWriter
-
-
-
-
Field Detail
-
DEFAULT_ENCODING
public static final String DEFAULT_ENCODING
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
setCoyoteResponse
public void setCoyoteResponse(Response coyoteResponse)
-
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
-
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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classWriter
- Throws:
IOException
- An underlying IOException occurred
-
flush
public void flush() throws IOException
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
protected void doFlush(boolean realFlush) throws IOException
Flush bytes or chars contained in the buffer.- Throws:
IOException
- An underlying IOException occurred
-
realWriteBytes
public void realWriteBytes(byte[] buf, int off, int cnt) throws IOException
Sends the buffer data to the client output, checking the state of Response and calling the right interceptors.- Specified by:
realWriteBytes
in interfaceorg.glassfish.grizzly.http.util.ByteChunk.ByteOutputChannel
- Parameters:
buf
- Byte buffer to be written to the responseoff
- Offsetcnt
- Length- Throws:
IOException
- An underlying IOException occurred
-
write
public void write(byte[] b, int off, int len) throws IOException
- Throws:
IOException
-
writeByte
public void writeByte(int b) throws IOException
- Throws:
IOException
-
write
public void write(int c) throws IOException
- Overrides:
write
in classWriter
- Throws:
IOException
-
write
public void write(char[] c) throws IOException
- Overrides:
write
in classWriter
- Throws:
IOException
-
write
public void write(char[] c, int off, int len) throws IOException
- Specified by:
write
in classWriter
- Throws:
IOException
-
write
public void write(String s, int off, int len) throws IOException
Append a string to the buffer- Overrides:
write
in classWriter
- Throws:
IOException
-
write
public void write(String s) throws IOException
- Overrides:
write
in classWriter
- Throws:
IOException
-
checkConverter
public void checkConverter() throws IOException
- Throws:
IOException
-
flushBytes
public void flushBytes() throws IOException
Real write - this buffer will be sent to the client- Throws:
IOException
-
getBytesWritten
public int getBytesWritten()
-
getCharsWritten
public int getCharsWritten()
-
getContentWritten
public int getContentWritten()
-
isNew
public boolean isNew()
True if this buffer hasn't been used ( since recycle() ) - i.e. no chars or bytes have been added to the buffer.
-
setBufferSize
public void setBufferSize(int size)
-
reset
public void reset()
-
getBufferSize
public int getBufferSize()
-
isReady
public boolean isReady()
-
setWriteListener
public void setWriteListener(jakarta.servlet.WriteListener writeListener)
-
hasData
public boolean hasData()
Are there any pending writes waiting to be flushed?
-
-