Package org.eclipse.jetty.server
Class HttpOutput
- java.lang.Object
-
- java.io.OutputStream
-
- javax.servlet.ServletOutputStream
-
- org.eclipse.jetty.server.HttpOutput
-
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,Runnable
public class HttpOutput extends ServletOutputStream implements Runnable
HttpOutputimplementsServletOutputStreamas required by the Servlet specification.HttpOutputbuffers content written by the application until a further write will overflow the buffer, at which point it triggers a commit of the response.HttpOutputcan be closed and reopened, to allow requests included viaRequestDispatcher.include(ServletRequest, ServletResponse)to close the stream, to be reopened after the inclusion ends.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceHttpOutput.InterceptorThe HttpOutput.Interceptor is a single intercept point for all output written to the HttpOutput: via writer; via output stream; asynchronously; or blocking.
-
Constructor Summary
Constructors Constructor Description HttpOutput(HttpChannel channel)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.eclipse.jetty.util.SharedBlockingCallback.BlockeracquireWriteBlockingCallback()voidclose()voidflush()intgetBufferSize()HttpChannelgetHttpChannel()HttpOutput.InterceptorgetInterceptor()longgetWritten()booleanisAllContentWritten()booleanisAsync()booleanisClosed()booleanisReady()booleanisWritten()voidonFlushed(long bytes)Invoked when bytes have been flushed to the network.voidprint(String s)voidrecycle()voidreopen()voidresetBuffer()voidrun()voidsendContent(InputStream in)Blocking send of stream content.voidsendContent(InputStream in, org.eclipse.jetty.util.Callback callback)Asynchronous send of stream content.voidsendContent(ByteBuffer content)Blocking send of whole content.voidsendContent(ByteBuffer content, org.eclipse.jetty.util.Callback callback)Asynchronous send of whole content.voidsendContent(ReadableByteChannel in)Blocking send of channel content.voidsendContent(ReadableByteChannel in, org.eclipse.jetty.util.Callback callback)Asynchronous send of channel content.voidsendContent(org.eclipse.jetty.http.HttpContent content)Blocking send of HTTP content.voidsendContent(org.eclipse.jetty.http.HttpContent httpContent, org.eclipse.jetty.util.Callback callback)Asynchronous send of HTTP content.voidsetBufferSize(int size)voidsetInterceptor(HttpOutput.Interceptor interceptor)voidsetWriteListener(WriteListener writeListener)StringtoString()voidwrite(byte[] b, int off, int len)voidwrite(int b)voidwrite(ByteBuffer buffer)protected voidwrite(ByteBuffer content, boolean complete, org.eclipse.jetty.util.Callback callback)-
Methods inherited from class javax.servlet.ServletOutputStream
print, print, print, print, print, print, println, println, println, println, println, println, println, println
-
Methods inherited from class java.io.OutputStream
nullOutputStream, write
-
-
-
-
Constructor Detail
-
HttpOutput
public HttpOutput(HttpChannel channel)
-
-
Method Detail
-
getHttpChannel
public HttpChannel getHttpChannel()
-
getInterceptor
public HttpOutput.Interceptor getInterceptor()
-
setInterceptor
public void setInterceptor(HttpOutput.Interceptor interceptor)
-
isWritten
public boolean isWritten()
-
getWritten
public long getWritten()
-
reopen
public void reopen()
-
isAllContentWritten
public boolean isAllContentWritten()
-
acquireWriteBlockingCallback
protected org.eclipse.jetty.util.SharedBlockingCallback.Blocker acquireWriteBlockingCallback() throws IOException- Throws:
IOException
-
write
protected void write(ByteBuffer content, boolean complete, org.eclipse.jetty.util.Callback callback)
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream
-
isClosed
public boolean isClosed()
-
isAsync
public boolean isAsync()
-
flush
public void flush() throws IOException- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
write
public void write(byte[] b, int off, int len) throws IOException- Overrides:
writein classOutputStream- Throws:
IOException
-
write
public void write(ByteBuffer buffer) throws IOException
- Throws:
IOException
-
write
public void write(int b) throws IOException- Specified by:
writein classOutputStream- Throws:
IOException
-
print
public void print(String s) throws IOException
- Overrides:
printin classServletOutputStream- Throws:
IOException
-
sendContent
public void sendContent(ByteBuffer content) throws IOException
Blocking send of whole content.- Parameters:
content- The whole content to send- Throws:
IOException- if the send fails
-
sendContent
public void sendContent(InputStream in) throws IOException
Blocking send of stream content.- Parameters:
in- The stream content to send- Throws:
IOException- if the send fails
-
sendContent
public void sendContent(ReadableByteChannel in) throws IOException
Blocking send of channel content.- Parameters:
in- The channel content to send- Throws:
IOException- if the send fails
-
sendContent
public void sendContent(org.eclipse.jetty.http.HttpContent content) throws IOExceptionBlocking send of HTTP content.- Parameters:
content- The HTTP content to send- Throws:
IOException- if the send fails
-
sendContent
public void sendContent(ByteBuffer content, org.eclipse.jetty.util.Callback callback)
Asynchronous send of whole content.- Parameters:
content- The whole content to sendcallback- The callback to use to notify success or failure
-
sendContent
public void sendContent(InputStream in, org.eclipse.jetty.util.Callback callback)
Asynchronous send of stream content. The stream will be closed after reading all content.- Parameters:
in- The stream content to sendcallback- The callback to use to notify success or failure
-
sendContent
public void sendContent(ReadableByteChannel in, org.eclipse.jetty.util.Callback callback)
Asynchronous send of channel content. The channel will be closed after reading all content.- Parameters:
in- The channel content to sendcallback- The callback to use to notify success or failure
-
sendContent
public void sendContent(org.eclipse.jetty.http.HttpContent httpContent, org.eclipse.jetty.util.Callback callback)Asynchronous send of HTTP content.- Parameters:
httpContent- The HTTP content to sendcallback- The callback to use to notify success or failure
-
getBufferSize
public int getBufferSize()
-
setBufferSize
public void setBufferSize(int size)
-
onFlushed
public void onFlushed(long bytes) throws IOExceptionInvoked when bytes have been flushed to the network.
The number of flushed bytes may be different from the bytes written by the application if an
HttpOutput.Interceptorchanged them, for example by compressing them.- Parameters:
bytes- the number of bytes flushed- Throws:
IOException- if the minimum data rate, when set, is not respected- See Also:
WriteFlusher.Listener
-
recycle
public void recycle()
-
resetBuffer
public void resetBuffer()
-
setWriteListener
public void setWriteListener(WriteListener writeListener)
- Specified by:
setWriteListenerin classServletOutputStream
-
isReady
public boolean isReady()
- Specified by:
isReadyin classServletOutputStream
-
-