If a content-length header was present when the stream was created then it will automatically close and flush itself once the appropriate amount of data has been written.
Once the listener has been set it goes into async mode, and writes become non blocking. Most methods have two different code paths, based on if the listener has been set or not
Once the write listener has been set operations must only be invoked on this stream from the write listener callback. Attempting to invoke from a different thread will result in an IllegalStateException.
Async listener tasks are queued in the AsyncContextImpl. At most one listener can be active at
one time, which simplifies the thread safety requirements.
| Modifier and Type | Class and Description |
|---|---|
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private AsyncContextImpl | |
| private volatile boolean | |
| private ByteBuffer | |
| private Integer | |
| private ByteBuffer[] | buffersToWrite
buffers that are queued up to be written via async writes. |
| private StreamSinkChannel | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private ServletOutputStreamImpl. | |
| private WriteListener | |
| private static final int | |
| private FileChannel | |
| private PooledByteBuffer | |
| private final ServletRequestContext | |
| private volatile int | |
| private static final AtomicIntegerFieldUpdater | |
| private long |
| Access | Constructor and Description |
|---|---|
| public | |
| public | ServletOutputStreamImpl(final ServletRequestContext servletRequestContext, int bufferSize)
Construct a new instance. |
| Modifier and Type | Method and Description |
|---|---|
| private ByteBuffer | |
| private void | |
| public void | close()
Overrides java. Implements java. Closes this output stream and releases any system resources associated with this stream. |
| public void | closeAsync()
Closes the channel, and flushes any data out using async IO This is used in two situations, if an output stream is not closed when a request is done, and when performing a close on a stream that is in async mode |
| private void | |
| public void | flush()
Overrides java. Implements java. Flushes this output stream and forces any buffered output bytes to be written out. |
| private boolean | |
| public void | |
| pack-priv ServletRequestContext | |
| public boolean | |
| public boolean | isReady()
Implements abstract jakarta. Returns true if data can be written without blocking else returns false. |
| pack-priv long | |
| public void | |
| public void | |
| private void | |
| public void | setWriteListener(final WriteListener
the writeListener)WriteListener that should be notified when it's possible to writeImplements abstract jakarta. Instructs the |
| public void | |
| pack-priv ByteBuffer | |
| pack-priv void | |
| pack-priv void | |
| public void | write(final int
the b)byte.Implements abstract java. Writes the specified byte to this output stream. |
| public void | write(final byte[]
the data. b)Overrides java. Writes |
| public void | write(final byte[]
the data. b, final int the start offset in the data. off, final int the number of bytes to write. len)Overrides java. Writes |
| public void | |
| public void | |
| private void | |
| private void | |
| private void |
| asyncContext | back to summary |
|---|---|
| private AsyncContextImpl asyncContext | |
| asyncIoStarted | back to summary |
|---|---|
| private volatile boolean asyncIoStarted | |
| buffer | back to summary |
|---|---|
| private ByteBuffer buffer | |
| bufferSize | back to summary |
|---|---|
| private Integer bufferSize | |
| buffersToWrite | back to summary |
|---|---|
| private ByteBuffer[] buffersToWrite buffers that are queued up to be written via async writes. This will include
| |
| channel | back to summary |
|---|---|
| private StreamSinkChannel channel | |
| FLAG_CLOSED | back to summary |
|---|---|
| private static final int FLAG_CLOSED | |
| FLAG_DELEGATE_SHUTDOWN | back to summary |
|---|---|
| private static final int FLAG_DELEGATE_SHUTDOWN | |
| FLAG_IN_CALLBACK | back to summary |
|---|---|
| private static final int FLAG_IN_CALLBACK | |
| FLAG_READY | back to summary |
|---|---|
| private static final int FLAG_READY | |
| FLAG_WRITE_STARTED | back to summary |
|---|---|
| private static final int FLAG_WRITE_STARTED | |
| internalListener | back to summary |
|---|---|
| private ServletOutputStreamImpl. | |
| listener | back to summary |
|---|---|
| private WriteListener listener | |
| MAX_BUFFERS_TO_ALLOCATE | back to summary |
|---|---|
| private static final int MAX_BUFFERS_TO_ALLOCATE | |
| pendingFile | back to summary |
|---|---|
| private FileChannel pendingFile | |
| pooledBuffer | back to summary |
|---|---|
| private PooledByteBuffer pooledBuffer | |
| servletRequestContext | back to summary |
|---|---|
| private final ServletRequestContext servletRequestContext | |
| state | back to summary |
|---|---|
| private volatile int state | |
| stateUpdater | back to summary |
|---|---|
| private static final AtomicIntegerFieldUpdater<ServletOutputStreamImpl> stateUpdater | |
| written | back to summary |
|---|---|
| private long written | |
| ServletOutputStreamImpl | back to summary |
|---|---|
| public ServletOutputStreamImpl(final ServletRequestContext servletRequestContext) Construct a new instance. No write timeout is configured. | |
| ServletOutputStreamImpl | back to summary |
|---|---|
| public ServletOutputStreamImpl(final ServletRequestContext servletRequestContext, int bufferSize) Construct a new instance. No write timeout is configured. | |
| buffer | back to summary |
|---|---|
| private ByteBuffer buffer() | |
| clearFlags | back to summary |
|---|---|
| private void clearFlags(int flags) | |
| close | back to summary |
|---|---|
| public void close() throws IOException Overrides java. Implements java. Doc from java. Closes this output stream and releases any system resources
associated with this stream. The general contract of
| |
| closeAsync | back to summary |
|---|---|
| public void closeAsync() throws IOException Closes the channel, and flushes any data out using async IO This is used in two situations, if an output stream is not closed when a request is done, and when performing a close on a stream that is in async mode | |
| createChannel | back to summary |
|---|---|
| private void createChannel() | |
| flush | back to summary |
|---|---|
| public void flush() throws IOException Overrides java. Implements java. Doc from java. Flushes this output stream and forces any buffered output bytes
to be written out. The general contract of If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.
| |
| flushBufferAsync | back to summary |
|---|---|
| private boolean flushBufferAsync(final boolean writeFinal) throws IOException | |
| flushInternal | back to summary |
|---|---|
| public void flushInternal() throws IOException | |
| getServletRequestContext | back to summary |
|---|---|
| pack-priv ServletRequestContext getServletRequestContext() | |
| isClosed | back to summary |
|---|---|
| public boolean isClosed() | |
| isReady | back to summary |
|---|---|
| public boolean isReady() Implements abstract jakarta. Doc from jakarta. Returns true if data can be written without blocking else returns false.
If this method returns false and a
| |
| remainingContentLength | back to summary |
|---|---|
| pack-priv long remainingContentLength() throws IOException | |
| resetBuffer | back to summary |
|---|---|
| public void resetBuffer() | |
| setBufferSize | back to summary |
|---|---|
| public void setBufferSize(final int size) | |
| setFlags | back to summary |
|---|---|
| private void setFlags(int flags) | |
| setWriteListener | back to summary |
|---|---|
| public void setWriteListener(final WriteListener writeListener) Implements abstract jakarta. Doc from jakarta. Instructs the
| |
| transferFrom | back to summary |
|---|---|
| public void transferFrom(FileChannel source) throws IOException Implements io.
| |
| underlyingBuffer | back to summary |
|---|---|
| pack-priv ByteBuffer underlyingBuffer() Returns the underlying buffer. If this has not been created yet then it is created.
Callers that use this method must call This allows the buffer to be filled directly, which can be more efficient. This method is basically a hack that should only be used by the print writer
| |
| updateWritten | back to summary |
|---|---|
| pack-priv void updateWritten(final long len) throws IOException | |
| updateWrittenAsync | back to summary |
|---|---|
| pack-priv void updateWrittenAsync(final long len) throws IOException | |
| write | back to summary |
|---|---|
| public void write(final int b) throws IOException Implements abstract java. Doc from java. Writes the specified byte to this output stream. The general
contract for
| |
| write | back to summary |
|---|---|
| public void write(final byte[] b) throws IOException Overrides java. Doc from java. Writes
| |
| write | back to summary |
|---|---|
| public void write(final byte[] b, final int off, final int len) throws IOException Overrides java. Doc from java. Writes
If
If
| |
| write | back to summary |
|---|---|
| public void write(ByteBuffer[] buffers) throws IOException Implements io.
| |
| write | back to summary |
|---|---|
| public void write(ByteBuffer byteBuffer) throws IOException Implements io.
| |
| writeAsync | back to summary |
|---|---|
| private void writeAsync(byte[] b, int off, int len) throws IOException | |
| writeBufferBlocking | back to summary |
|---|---|
| private void writeBufferBlocking(final boolean writeFinal) throws IOException | |
| writeTooLargeForBuffer | back to summary |
|---|---|
| private void writeTooLargeForBuffer(byte[] b, int off, int len, ByteBuffer buffer) throws IOException | |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public void | handleEvent(final StreamSinkChannel
the channel event aChannel)Implements org. Handle the event on this channel. |
| WriteChannelListener | back to summary |
|---|---|
| private WriteChannelListener() | |
| handleError | back to summary |
|---|---|
| private void handleError(final Throwable t) | |
| handleEvent | back to summary |
|---|---|
| public void handleEvent(final StreamSinkChannel aChannel) Implements org. Doc from org. Handle the event on this channel.
| |