Class ServletOutputStreamImpl
- All Implemented Interfaces:
io.undertow.io.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 TypeMethodDescriptionvoid
close()
void
Closes the channel, and flushes any data out using async IOvoid
flush()
void
boolean
isClosed()
boolean
isReady()
void
void
setBufferSize
(int size) void
setWriteListener
(javax.servlet.WriteListener writeListener) void
transferFrom
(FileChannel source) void
write
(byte[] b) void
write
(byte[] b, int off, int len) void
write
(int b) void
write
(ByteBuffer byteBuffer) void
write
(ByteBuffer[] buffers) Methods inherited from class javax.servlet.ServletOutputStream
print, print, print, print, print, print, print, println, println, println, println, println, println, println, println
Methods 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:
write
in classOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
write
- Specified by:
write
in interfaceio.undertow.io.BufferWritableOutputStream
- Throws:
IOException
-
write
- Specified by:
write
in interfaceio.undertow.io.BufferWritableOutputStream
- Throws:
IOException
-
flush
- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
-
flushInternal
- Throws:
IOException
-
transferFrom
- Specified by:
transferFrom
in interfaceio.undertow.io.BufferWritableOutputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in 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()- Specified by:
isReady
in classjavax.servlet.ServletOutputStream
-
setWriteListener
public void setWriteListener(javax.servlet.WriteListener writeListener) - Specified by:
setWriteListener
in classjavax.servlet.ServletOutputStream
-