Class ServletOutputStreamImpl
- All Implemented Interfaces:
BufferWritableOutputStream,Closeable,Flushable,AutoCloseable
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.
- Author:
- Stuart Douglas
-
Constructor Summary
ConstructorsConstructorDescriptionServletOutputStreamImpl(ServletRequestContext servletRequestContext) Construct a new instance.ServletOutputStreamImpl(ServletRequestContext servletRequestContext, int bufferSize) Construct a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidCloses the channel, and flushes any data out using async IOvoidflush()voidbooleanisClosed()booleanisReady()Returns true if data can be written without blocking else returns false.voidvoidsetBufferSize(int size) voidsetWriteListener(WriteListener writeListener) Instructs theServletOutputStreamto invoke the providedWriteListenerwhen it is possible to writevoidtransferFrom(FileChannel source) voidwrite(byte[] b) voidwrite(byte[] b, int off, int len) voidwrite(int b) voidwrite(ByteBuffer byteBuffer) voidwrite(ByteBuffer[] buffers) Methods inherited from class jakarta.servlet.ServletOutputStream
print, print, print, print, print, print, print, println, println, println, println, println, println, println, printlnMethods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
ServletOutputStreamImpl
Construct a new instance. No write timeout is configured. -
ServletOutputStreamImpl
Construct a new instance. No write timeout is configured.
-
-
Method Details
-
write
- Specified by:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
write
- Specified by:
writein interfaceBufferWritableOutputStream- Throws:
IOException
-
write
- Specified by:
writein interfaceBufferWritableOutputStream- Throws:
IOException
-
flush
- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
flushInternal
- Throws:
IOException
-
transferFrom
- Specified by:
transferFromin interfaceBufferWritableOutputStream- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-
closeAsync
Closes the channel, and flushes any data out using async IOThis 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
- Throws:
IOException
-
resetBuffer
public void resetBuffer() -
setBufferSize
public void setBufferSize(int size) -
isClosed
public boolean isClosed() -
isReady
public boolean isReady()Description copied from class:ServletOutputStreamReturns true if data can be written without blocking else returns false.If this method returns false and a
WriteListenerhas been set withServletOutputStream.setWriteListener(WriteListener), then container will subsequently invokeWriteListener.onWritePossible()once a write operation becomes possible without blocking. Other than the initial call,WriteListener.onWritePossible()will only be called if and only if this method is called and returns false.- Specified by:
isReadyin classServletOutputStream- Returns:
trueif data can be written without blocking, otherwise returnsfalse.- See Also:
-
setWriteListener
Description copied from class:ServletOutputStreamInstructs theServletOutputStreamto invoke the providedWriteListenerwhen it is possible to write- Specified by:
setWriteListenerin classServletOutputStream- Parameters:
writeListener- theWriteListenerthat should be notified when it's possible to write
-