Package io.undertow.servlet.spec
Class ServletOutputStreamImpl
- java.lang.Object
-
- java.io.OutputStream
-
- jakarta.servlet.ServletOutputStream
-
- io.undertow.servlet.spec.ServletOutputStreamImpl
-
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
public class ServletOutputStreamImpl extends jakarta.servlet.ServletOutputStreamThis stream essentially has two modes. When it is being used in standard blocking mode then it will buffer in the pooled buffer. If the stream is closed before the buffer is full it will set a content-length header if one has not been explicitly set.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
Constructors Constructor Description ServletOutputStreamImpl(io.undertow.server.HttpServerExchange exchange)Construct a new instance.ServletOutputStreamImpl(io.undertow.server.HttpServerExchange exchange, Integer bufferSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidflush()io.netty.buffer.ByteBufflushInternal()longgetBytesWritten()ServletRequestContextgetServletRequestContext()booleanisReady()voidresetBuffer()voidsetBufferSize(int bufferSize)voidsetWriteListener(jakarta.servlet.WriteListener writeListener)io.netty.buffer.ByteBufunderlyingBuffer()voidupdateWritten(int len)voidwrite(byte[] b)voidwrite(byte[] b, int off, int len)voidwrite(int b)-
Methods inherited from class jakarta.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 Detail
-
ServletOutputStreamImpl
public ServletOutputStreamImpl(io.undertow.server.HttpServerExchange exchange)
Construct a new instance. No write timeout is configured.- Parameters:
exchange- The exchange
-
ServletOutputStreamImpl
public ServletOutputStreamImpl(io.undertow.server.HttpServerExchange exchange, Integer bufferSize)
-
-
Method Detail
-
getBytesWritten
public long getBytesWritten()
-
write
public void write(int b) throws IOException- Specified by:
writein classOutputStream- Throws:
IOException
-
write
public void write(byte[] b) throws IOException- Overrides:
writein classOutputStream- Throws:
IOException
-
write
public void write(byte[] b, int off, int len) throws IOException- Overrides:
writein classOutputStream- Throws:
IOException
-
flush
public void flush() throws IOException- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-
resetBuffer
public void resetBuffer()
-
setBufferSize
public void setBufferSize(int bufferSize)
-
getServletRequestContext
public ServletRequestContext getServletRequestContext()
-
underlyingBuffer
public io.netty.buffer.ByteBuf underlyingBuffer()
-
flushInternal
public io.netty.buffer.ByteBuf flushInternal() throws IOException- Throws:
IOException
-
updateWritten
public void updateWritten(int len)
-
isReady
public boolean isReady()
- Specified by:
isReadyin classjakarta.servlet.ServletOutputStream
-
setWriteListener
public void setWriteListener(jakarta.servlet.WriteListener writeListener)
- Specified by:
setWriteListenerin classjakarta.servlet.ServletOutputStream
-
-