public class HttpOutput
extends javax.servlet.ServletOutputStream
implements java.lang.Runnable
HttpOutput
implements ServletOutputStream
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
via RequestDispatcher.include(ServletRequest, ServletResponse)
to
close the stream, to be reopened after the inclusion ends.
Modifier and Type | Class and Description |
---|---|
(package private) static class |
HttpOutput.ApiState
The API State which combines with the output State:
|
private class |
HttpOutput.AsyncFlush |
private class |
HttpOutput.AsyncWrite |
private class |
HttpOutput.ChannelWriteCB |
private class |
HttpOutput.InputStreamWritingCB
An iterating callback that will take content from an
InputStream and write it to the associated
HttpChannel . |
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.
|
private class |
HttpOutput.NestedChannelWriteCB |
private class |
HttpOutput.ReadableByteChannelWritingCB
An iterating callback that will take content from a
ReadableByteChannel and write it to the
HttpChannel . |
(package private) static class |
HttpOutput.State
The output state
|
private static class |
HttpOutput.WriteBlocker |
private class |
HttpOutput.WriteCompleteCB |
Modifier and Type | Field and Description |
---|---|
private java.nio.ByteBuffer |
_aggregate |
private HttpOutput.ApiState |
_apiState |
private int |
_bufferSize |
private HttpChannel |
_channel |
private HttpChannelState |
_channelState |
private Callback |
_closedCallback |
private int |
_commitSize |
private static java.lang.ThreadLocal<java.nio.charset.CharsetEncoder> |
_encoder |
private long |
_firstByteTimeStamp |
private long |
_flushed |
private HttpOutput.Interceptor |
_interceptor |
private java.lang.Throwable |
_onError |
private boolean |
_softClose |
private HttpOutput.State |
_state |
private SharedBlockingCallback |
_writeBlocker |
private javax.servlet.WriteListener |
_writeListener |
private long |
_written |
private static Logger |
LOG |
private static java.lang.String |
LSTRING_FILE |
private static java.util.ResourceBundle |
lStrings |
Constructor and Description |
---|
HttpOutput(HttpChannel channel) |
Modifier and Type | Method and Description |
---|---|
private java.nio.ByteBuffer |
acquireBuffer() |
protected SharedBlockingCallback.Blocker |
acquireWriteBlockingCallback() |
private void |
channelWrite(java.nio.ByteBuffer content,
boolean complete) |
private void |
channelWrite(java.nio.ByteBuffer content,
boolean last,
Callback callback) |
private void |
checkWritable() |
void |
close() |
void |
complete(Callback callback) |
void |
completed()
Called to indicate that the request cycle has been completed.
|
void |
flush() |
java.nio.ByteBuffer |
getBuffer() |
int |
getBufferSize() |
HttpChannel |
getHttpChannel() |
HttpOutput.Interceptor |
getInterceptor() |
long |
getWritten() |
boolean |
isAsync() |
boolean |
isClosed() |
boolean |
isReady() |
boolean |
isWritten() |
private int |
maximizeAggregateSpace() |
void |
onFlushed(long bytes)
Invoked when bytes have been flushed to the network.
|
private void |
onWriteComplete(boolean last,
java.lang.Throwable failure) |
private boolean |
prepareSendContent(int len,
Callback callback) |
void |
print(java.lang.String s) |
private void |
print(java.lang.String s,
boolean eoln) |
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() |
private void |
releaseBuffer() |
void |
reopen() |
void |
resetBuffer() |
void |
run() |
void |
sendContent(java.nio.ByteBuffer content)
Blocking send of whole content.
|
void |
sendContent(java.nio.ByteBuffer content,
Callback callback)
Asynchronous send of whole content.
|
void |
sendContent(HttpContent content)
Blocking send of HTTP content.
|
void |
sendContent(HttpContent httpContent,
Callback callback)
Asynchronous send of HTTP content.
|
void |
sendContent(java.io.InputStream in)
Blocking send of stream content.
|
void |
sendContent(java.io.InputStream in,
Callback callback)
Asynchronous send of stream content.
|
void |
sendContent(java.nio.channels.ReadableByteChannel in)
Blocking send of channel content.
|
void |
sendContent(java.nio.channels.ReadableByteChannel in,
Callback callback)
Asynchronous send of channel content.
|
void |
setBufferSize(int size) |
void |
setInterceptor(HttpOutput.Interceptor interceptor) |
void |
setWriteListener(javax.servlet.WriteListener writeListener) |
void |
softClose() |
private java.lang.String |
stateString() |
java.lang.String |
toString() |
private boolean |
updateApiState(java.lang.Throwable failure) |
void |
write(byte[] b,
int off,
int len) |
void |
write(java.nio.ByteBuffer buffer) |
void |
write(int b) |
private static final java.lang.String LSTRING_FILE
private static java.util.ResourceBundle lStrings
private static Logger LOG
private static final java.lang.ThreadLocal<java.nio.charset.CharsetEncoder> _encoder
private final HttpChannel _channel
private final HttpChannelState _channelState
private final SharedBlockingCallback _writeBlocker
private HttpOutput.ApiState _apiState
private HttpOutput.State _state
private boolean _softClose
private HttpOutput.Interceptor _interceptor
private long _written
private long _flushed
private long _firstByteTimeStamp
private java.nio.ByteBuffer _aggregate
private int _bufferSize
private int _commitSize
private javax.servlet.WriteListener _writeListener
private volatile java.lang.Throwable _onError
private Callback _closedCallback
public HttpOutput(HttpChannel channel)
public HttpChannel getHttpChannel()
public HttpOutput.Interceptor getInterceptor()
public void setInterceptor(HttpOutput.Interceptor interceptor)
public boolean isWritten()
public long getWritten()
public void reopen()
protected SharedBlockingCallback.Blocker acquireWriteBlockingCallback() throws java.io.IOException
java.io.IOException
private void channelWrite(java.nio.ByteBuffer content, boolean complete) throws java.io.IOException
java.io.IOException
private void channelWrite(java.nio.ByteBuffer content, boolean last, Callback callback)
private void onWriteComplete(boolean last, java.lang.Throwable failure)
private boolean updateApiState(java.lang.Throwable failure)
private int maximizeAggregateSpace()
public void softClose()
public void complete(Callback callback)
public void completed()
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.OutputStream
java.io.IOException
public java.nio.ByteBuffer getBuffer()
private java.nio.ByteBuffer acquireBuffer()
private void releaseBuffer()
public boolean isClosed()
public boolean isAsync()
public void flush() throws java.io.IOException
flush
in interface java.io.Flushable
flush
in class java.io.OutputStream
java.io.IOException
private void checkWritable() throws EofException
EofException
public void write(byte[] b, int off, int len) throws java.io.IOException
write
in class java.io.OutputStream
java.io.IOException
public void write(java.nio.ByteBuffer buffer) throws java.io.IOException
java.io.IOException
public void write(int b) throws java.io.IOException
write
in class java.io.OutputStream
java.io.IOException
public void print(java.lang.String s) throws java.io.IOException
print
in class javax.servlet.ServletOutputStream
java.io.IOException
public void println(java.lang.String s) throws java.io.IOException
println
in class javax.servlet.ServletOutputStream
java.io.IOException
private void print(java.lang.String s, boolean eoln) throws java.io.IOException
java.io.IOException
public void println(boolean b) throws java.io.IOException
println
in class javax.servlet.ServletOutputStream
java.io.IOException
public void println(char c) throws java.io.IOException
println
in class javax.servlet.ServletOutputStream
java.io.IOException
public void println(int i) throws java.io.IOException
println
in class javax.servlet.ServletOutputStream
java.io.IOException
public void println(long l) throws java.io.IOException
println
in class javax.servlet.ServletOutputStream
java.io.IOException
public void println(float f) throws java.io.IOException
println
in class javax.servlet.ServletOutputStream
java.io.IOException
public void println(double d) throws java.io.IOException
println
in class javax.servlet.ServletOutputStream
java.io.IOException
public void sendContent(java.nio.ByteBuffer content) throws java.io.IOException
content
- The whole content to sendjava.io.IOException
- if the send failspublic void sendContent(java.io.InputStream in) throws java.io.IOException
in
- The stream content to sendjava.io.IOException
- if the send failspublic void sendContent(java.nio.channels.ReadableByteChannel in) throws java.io.IOException
in
- The channel content to sendjava.io.IOException
- if the send failspublic void sendContent(HttpContent content) throws java.io.IOException
content
- The HTTP content to sendjava.io.IOException
- if the send failspublic void sendContent(java.nio.ByteBuffer content, Callback callback)
content
- The whole content to sendcallback
- The callback to use to notify success or failurepublic void sendContent(java.io.InputStream in, Callback callback)
in
- The stream content to sendcallback
- The callback to use to notify success or failurepublic void sendContent(java.nio.channels.ReadableByteChannel in, Callback callback)
in
- The channel content to sendcallback
- The callback to use to notify success or failureprivate boolean prepareSendContent(int len, Callback callback)
public void sendContent(HttpContent httpContent, Callback callback)
httpContent
- The HTTP content to sendcallback
- The callback to use to notify success or failurepublic int getBufferSize()
public void setBufferSize(int size)
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.
bytes
- the number of bytes flushedjava.io.IOException
- if the minimum data rate, when set, is not respectedWriteFlusher.Listener
public void recycle()
public void resetBuffer()
public void setWriteListener(javax.servlet.WriteListener writeListener)
setWriteListener
in class javax.servlet.ServletOutputStream
public boolean isReady()
isReady
in class javax.servlet.ServletOutputStream
public void run()
run
in interface java.lang.Runnable
private java.lang.String stateString()
public java.lang.String toString()
toString
in class java.lang.Object