Package org.eclipse.jetty.server
Class HttpOutput
- java.lang.Object
-
- java.io.OutputStream
-
- javax.servlet.ServletOutputStream
-
- org.eclipse.jetty.server.HttpOutput
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
,java.lang.Runnable
public class HttpOutput extends javax.servlet.ServletOutputStream implements java.lang.Runnable
HttpOutput
implementsServletOutputStream
as required by the Servlet specification.HttpOutput
buffers content written by the application until a further write will overflow the buffer, at which point it triggers a commit of the response.HttpOutput
can 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 interface
HttpOutput.Interceptor
The 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 java.nio.ByteBuffer
acquireBuffer()
protected org.eclipse.jetty.util.SharedBlockingCallback.Blocker
acquireWriteBlockingCallback()
void
close()
void
close(java.io.Closeable wrapper, org.eclipse.jetty.util.Callback callback)
void
closed()
Called to indicate that the last write has been performed.void
closedBySendError()
void
flush()
java.nio.ByteBuffer
getBuffer()
int
getBufferSize()
HttpChannel
getHttpChannel()
HttpOutput.Interceptor
getInterceptor()
long
getWritten()
boolean
isAllContentWritten()
boolean
isAsync()
boolean
isClosed()
boolean
isReady()
boolean
isWritten()
void
onFlushed(long bytes)
Invoked when bytes have been flushed to the network.void
print(java.lang.String s)
void
println(boolean b)
void
println(char c)
void
println(double d)
void
println(float f)
void
println(int i)
void
println(long l)
void
println(java.lang.String s)
void
recycle()
void
reopen()
void
resetBuffer()
void
run()
void
sendContent(java.io.InputStream in)
Blocking send of stream content.void
sendContent(java.io.InputStream in, org.eclipse.jetty.util.Callback callback)
Asynchronous send of stream content.void
sendContent(java.nio.ByteBuffer content)
Blocking send of whole content.void
sendContent(java.nio.ByteBuffer content, org.eclipse.jetty.util.Callback callback)
Asynchronous send of whole content.void
sendContent(java.nio.channels.ReadableByteChannel in)
Blocking send of channel content.void
sendContent(java.nio.channels.ReadableByteChannel in, org.eclipse.jetty.util.Callback callback)
Asynchronous send of channel content.void
sendContent(org.eclipse.jetty.http.HttpContent content)
Blocking send of HTTP content.void
sendContent(org.eclipse.jetty.http.HttpContent httpContent, org.eclipse.jetty.util.Callback callback)
Asynchronous send of HTTP content.void
setBufferSize(int size)
void
setInterceptor(HttpOutput.Interceptor interceptor)
void
setWriteListener(javax.servlet.WriteListener writeListener)
java.lang.String
toString()
void
write(byte[] b, int off, int len)
void
write(int b)
void
write(java.nio.ByteBuffer buffer)
protected void
write(java.nio.ByteBuffer content, boolean complete, org.eclipse.jetty.util.Callback callback)
-
-
-
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 java.io.IOException
- Throws:
java.io.IOException
-
write
protected void write(java.nio.ByteBuffer content, boolean complete, org.eclipse.jetty.util.Callback callback)
-
closedBySendError
public void closedBySendError()
-
close
public void close(java.io.Closeable wrapper, org.eclipse.jetty.util.Callback callback)
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.OutputStream
-
closed
public void closed()
Called to indicate that the last write has been performed. It updates the state and performs cleanup operations.
-
getBuffer
public java.nio.ByteBuffer getBuffer()
-
acquireBuffer
public java.nio.ByteBuffer acquireBuffer()
-
isClosed
public boolean isClosed()
-
isAsync
public boolean isAsync()
-
flush
public void flush() throws java.io.IOException
- Specified by:
flush
in interfacejava.io.Flushable
- Overrides:
flush
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(java.nio.ByteBuffer buffer) throws java.io.IOException
- Throws:
java.io.IOException
-
write
public void write(int b) throws java.io.IOException
- Specified by:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
print
public void print(java.lang.String s) throws java.io.IOException
- Overrides:
print
in classjavax.servlet.ServletOutputStream
- Throws:
java.io.IOException
-
println
public void println(java.lang.String s) throws java.io.IOException
- Overrides:
println
in classjavax.servlet.ServletOutputStream
- Throws:
java.io.IOException
-
println
public void println(boolean b) throws java.io.IOException
- Overrides:
println
in classjavax.servlet.ServletOutputStream
- Throws:
java.io.IOException
-
println
public void println(char c) throws java.io.IOException
- Overrides:
println
in classjavax.servlet.ServletOutputStream
- Throws:
java.io.IOException
-
println
public void println(int i) throws java.io.IOException
- Overrides:
println
in classjavax.servlet.ServletOutputStream
- Throws:
java.io.IOException
-
println
public void println(long l) throws java.io.IOException
- Overrides:
println
in classjavax.servlet.ServletOutputStream
- Throws:
java.io.IOException
-
println
public void println(float f) throws java.io.IOException
- Overrides:
println
in classjavax.servlet.ServletOutputStream
- Throws:
java.io.IOException
-
println
public void println(double d) throws java.io.IOException
- Overrides:
println
in classjavax.servlet.ServletOutputStream
- Throws:
java.io.IOException
-
sendContent
public void sendContent(java.nio.ByteBuffer content) throws java.io.IOException
Blocking send of whole content.- Parameters:
content
- The whole content to send- Throws:
java.io.IOException
- if the send fails
-
sendContent
public void sendContent(java.io.InputStream in) throws java.io.IOException
Blocking send of stream content.- Parameters:
in
- The stream content to send- Throws:
java.io.IOException
- if the send fails
-
sendContent
public void sendContent(java.nio.channels.ReadableByteChannel in) throws java.io.IOException
Blocking send of channel content.- Parameters:
in
- The channel content to send- Throws:
java.io.IOException
- if the send fails
-
sendContent
public void sendContent(org.eclipse.jetty.http.HttpContent content) throws java.io.IOException
Blocking send of HTTP content.- Parameters:
content
- The HTTP content to send- Throws:
java.io.IOException
- if the send fails
-
sendContent
public void sendContent(java.nio.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(java.io.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(java.nio.channels.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 java.io.IOException
Invoked 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.Interceptor
changed them, for example by compressing them.- Parameters:
bytes
- the number of bytes flushed- Throws:
java.io.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(javax.servlet.WriteListener writeListener)
- Specified by:
setWriteListener
in classjavax.servlet.ServletOutputStream
-
isReady
public boolean isReady()
- Specified by:
isReady
in classjavax.servlet.ServletOutputStream
-
run
public void run()
- Specified by:
run
in interfacejava.lang.Runnable
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-