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.RunnableHttpOutputimplementsServletOutputStreamas 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 (package private) static classHttpOutput.ApiStateThe API State which combines with the output State:private classHttpOutput.AsyncFlushprivate classHttpOutput.AsyncWriteprivate classHttpOutput.ChannelWriteCBprivate classHttpOutput.InputStreamWritingCBAn iterating callback that will take content from an InputStream and write it to the associatedHttpChannel.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.private classHttpOutput.NestedChannelWriteCBprivate classHttpOutput.ReadableByteChannelWritingCBAn iterating callback that will take content from a ReadableByteChannel and write it to theHttpChannel.(package private) static classHttpOutput.StateThe output stateprivate static classHttpOutput.WriteBlockerprivate classHttpOutput.WriteCompleteCB
-
Field Summary
Fields Modifier and Type Field Description private java.nio.ByteBuffer_aggregateprivate HttpOutput.ApiState_apiStateprivate int_bufferSizeprivate HttpChannel_channelprivate HttpChannelState_channelStateprivate Callback_closedCallbackprivate int_commitSizeprivate static java.lang.ThreadLocal<java.nio.charset.CharsetEncoder>_encoderprivate long_firstByteTimeStampprivate long_flushedprivate HttpOutput.Interceptor_interceptorprivate java.lang.Throwable_onErrorprivate boolean_softCloseprivate HttpOutput.State_stateprivate SharedBlockingCallback_writeBlockerprivate javax.servlet.WriteListener_writeListenerprivate long_writtenprivate static LoggerLOGprivate static java.lang.StringLSTRING_FILEprivate static java.util.ResourceBundlelStrings
-
Constructor Summary
Constructors Constructor Description HttpOutput(HttpChannel channel)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.nio.ByteBufferacquireBuffer()protected SharedBlockingCallback.BlockeracquireWriteBlockingCallback()private voidchannelWrite(java.nio.ByteBuffer content, boolean complete)private voidchannelWrite(java.nio.ByteBuffer content, boolean last, Callback callback)private voidcheckWritable()voidclose()voidcomplete(Callback callback)voidcompleted(java.lang.Throwable failure)Called to indicate that the request cycle has been completed.voidflush()java.nio.ByteBuffergetBuffer()intgetBufferSize()HttpChannelgetHttpChannel()HttpOutput.InterceptorgetInterceptor()longgetWritten()booleanisAsync()booleanisClosed()booleanisReady()booleanisWritten()private intmaximizeAggregateSpace()voidonFlushed(long bytes)Invoked when bytes have been flushed to the network.private voidonWriteComplete(boolean last, java.lang.Throwable failure)private booleanprepareSendContent(int len, Callback callback)voidprint(java.lang.String s)private voidprint(java.lang.String s, boolean eoln)voidprintln(boolean b)voidprintln(char c)voidprintln(double d)voidprintln(float f)voidprintln(int i)voidprintln(long l)voidprintln(java.lang.String s)voidrecycle()private voidreleaseBuffer(java.lang.Throwable failure)voidreopen()voidresetBuffer()voidrun()voidsendContent(java.io.InputStream in)Blocking send of stream content.voidsendContent(java.io.InputStream in, Callback callback)Asynchronous send of stream content.voidsendContent(java.nio.ByteBuffer content)Blocking send of whole content.voidsendContent(java.nio.ByteBuffer content, Callback callback)Asynchronous send of whole content.voidsendContent(java.nio.channels.ReadableByteChannel in)Blocking send of channel content.voidsendContent(java.nio.channels.ReadableByteChannel in, Callback callback)Asynchronous send of channel content.voidsendContent(HttpContent content)Blocking send of HTTP content.voidsendContent(HttpContent httpContent, Callback callback)Asynchronous send of HTTP content.voidsetBufferSize(int size)voidsetInterceptor(HttpOutput.Interceptor interceptor)voidsetWriteListener(javax.servlet.WriteListener writeListener)voidsoftClose()private java.lang.StringstateString()java.lang.StringtoString()private booleanupdateApiState(java.lang.Throwable failure)voidwrite(byte[] b, int off, int len)voidwrite(int b)voidwrite(java.nio.ByteBuffer buffer)
-
-
-
Field Detail
-
LSTRING_FILE
private static final java.lang.String LSTRING_FILE
- See Also:
- Constant Field Values
-
lStrings
private static java.util.ResourceBundle lStrings
-
LOG
private static Logger LOG
-
_encoder
private static final java.lang.ThreadLocal<java.nio.charset.CharsetEncoder> _encoder
-
_channel
private final HttpChannel _channel
-
_channelState
private final HttpChannelState _channelState
-
_writeBlocker
private final SharedBlockingCallback _writeBlocker
-
_apiState
private HttpOutput.ApiState _apiState
-
_state
private HttpOutput.State _state
-
_softClose
private boolean _softClose
-
_interceptor
private HttpOutput.Interceptor _interceptor
-
_written
private long _written
-
_flushed
private long _flushed
-
_firstByteTimeStamp
private long _firstByteTimeStamp
-
_aggregate
private java.nio.ByteBuffer _aggregate
-
_bufferSize
private int _bufferSize
-
_commitSize
private int _commitSize
-
_writeListener
private javax.servlet.WriteListener _writeListener
-
_onError
private volatile java.lang.Throwable _onError
-
_closedCallback
private Callback _closedCallback
-
-
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()
-
acquireWriteBlockingCallback
protected SharedBlockingCallback.Blocker acquireWriteBlockingCallback() throws java.io.IOException
- Throws:
java.io.IOException
-
channelWrite
private void channelWrite(java.nio.ByteBuffer content, boolean complete) throws java.io.IOException- Throws:
java.io.IOException
-
channelWrite
private void channelWrite(java.nio.ByteBuffer content, boolean last, Callback callback)
-
onWriteComplete
private void onWriteComplete(boolean last, java.lang.Throwable failure)
-
updateApiState
private boolean updateApiState(java.lang.Throwable failure)
-
maximizeAggregateSpace
private int maximizeAggregateSpace()
-
softClose
public void softClose()
-
complete
public void complete(Callback callback)
-
completed
public void completed(java.lang.Throwable failure)
Called to indicate that the request cycle has been completed.
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.OutputStream- Throws:
java.io.IOException
-
getBuffer
public java.nio.ByteBuffer getBuffer()
-
acquireBuffer
private java.nio.ByteBuffer acquireBuffer()
-
releaseBuffer
private void releaseBuffer(java.lang.Throwable failure)
-
isClosed
public boolean isClosed()
-
isAsync
public boolean isAsync()
-
flush
public void flush() throws java.io.IOException- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.OutputStream- Throws:
java.io.IOException
-
checkWritable
private void checkWritable() throws EofException- Throws:
EofException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException- Overrides:
writein 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:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
print
public void print(java.lang.String s) throws java.io.IOException- Overrides:
printin classjavax.servlet.ServletOutputStream- Throws:
java.io.IOException
-
println
public void println(java.lang.String s) throws java.io.IOException- Overrides:
printlnin classjavax.servlet.ServletOutputStream- Throws:
java.io.IOException
-
print
private void print(java.lang.String s, boolean eoln) throws java.io.IOException- Throws:
java.io.IOException
-
println
public void println(boolean b) throws java.io.IOException- Overrides:
printlnin classjavax.servlet.ServletOutputStream- Throws:
java.io.IOException
-
println
public void println(char c) throws java.io.IOException- Overrides:
printlnin classjavax.servlet.ServletOutputStream- Throws:
java.io.IOException
-
println
public void println(int i) throws java.io.IOException- Overrides:
printlnin classjavax.servlet.ServletOutputStream- Throws:
java.io.IOException
-
println
public void println(long l) throws java.io.IOException- Overrides:
printlnin classjavax.servlet.ServletOutputStream- Throws:
java.io.IOException
-
println
public void println(float f) throws java.io.IOException- Overrides:
printlnin classjavax.servlet.ServletOutputStream- Throws:
java.io.IOException
-
println
public void println(double d) throws java.io.IOException- Overrides:
printlnin classjavax.servlet.ServletOutputStream- Throws:
java.io.IOException
-
sendContent
public void sendContent(java.nio.ByteBuffer content) throws java.io.IOExceptionBlocking 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.IOExceptionBlocking 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.IOExceptionBlocking send of channel content.- Parameters:
in- The channel content to send- Throws:
java.io.IOException- if the send fails
-
sendContent
public void sendContent(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, 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, 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, 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
-
prepareSendContent
private boolean prepareSendContent(int len, Callback callback)
-
sendContent
public void sendContent(HttpContent httpContent, 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.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:
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:
setWriteListenerin classjavax.servlet.ServletOutputStream
-
isReady
public boolean isReady()
- Specified by:
isReadyin classjavax.servlet.ServletOutputStream
-
run
public void run()
- Specified by:
runin interfacejava.lang.Runnable
-
stateString
private java.lang.String stateString()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-