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
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static enum
The API State which combines with the output State:private class
private class
private class
private class
An iterating callback that will take content from an InputStream and write it to the associatedHttpChannel
.static interface
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
private class
An iterating callback that will take content from a ReadableByteChannel and write it to theHttpChannel
.(package private) static enum
The output stateprivate static class
private class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ByteBuffer
private HttpOutput.ApiState
private int
private final HttpChannel
private final HttpChannelState
private Callback
private int
private static final ThreadLocal
<CharsetEncoder> private long
private long
private HttpOutput.Interceptor
private Throwable
private boolean
private HttpOutput.State
private final SharedBlockingCallback
private javax.servlet.WriteListener
private long
private static Logger
private static final String
private static ResourceBundle
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate ByteBuffer
protected SharedBlockingCallback.Blocker
private void
channelWrite
(ByteBuffer content, boolean complete) private void
channelWrite
(ByteBuffer content, boolean last, Callback callback) private void
void
close()
void
void
Called to indicate that the request cycle has been completed.void
flush()
int
long
boolean
isAsync()
boolean
isClosed()
boolean
isReady()
boolean
private int
void
onFlushed
(long bytes) Invoked when bytes have been flushed to the network.private void
onWriteComplete
(boolean last, Throwable failure) private boolean
prepareSendContent
(int len, Callback callback) void
private void
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
void
recycle()
private void
releaseBuffer
(Throwable failure) void
reopen()
void
void
run()
void
Blocking send of stream content.void
sendContent
(InputStream in, Callback callback) Asynchronous send of stream content.void
sendContent
(ByteBuffer content) Blocking send of whole content.void
sendContent
(ByteBuffer content, Callback callback) Asynchronous send of whole content.void
Blocking send of channel content.void
sendContent
(ReadableByteChannel in, Callback callback) Asynchronous send of channel content.void
sendContent
(HttpContent content) Blocking send of HTTP content.void
sendContent
(HttpContent httpContent, Callback callback) Asynchronous send of HTTP content.void
setBufferSize
(int size) void
setInterceptor
(HttpOutput.Interceptor interceptor) void
setWriteListener
(javax.servlet.WriteListener writeListener) void
private String
toString()
private boolean
updateApiState
(Throwable failure) void
write
(byte[] b, int off, int len) void
write
(int b) void
write
(ByteBuffer buffer) Methods inherited from class javax.servlet.ServletOutputStream
print, print, print, print, print, print, println
Methods inherited from class java.io.OutputStream
nullOutputStream, write
-
Field Details
-
LSTRING_FILE
- See Also:
-
lStrings
-
LOG
-
_encoder
-
_channel
-
_channelState
-
_writeBlocker
-
_apiState
-
_state
-
_softClose
private boolean _softClose -
_interceptor
-
_written
private long _written -
_flushed
private long _flushed -
_firstByteTimeStamp
private long _firstByteTimeStamp -
_aggregate
-
_bufferSize
private int _bufferSize -
_commitSize
private int _commitSize -
_writeListener
private javax.servlet.WriteListener _writeListener -
_onError
-
_closedCallback
-
-
Constructor Details
-
HttpOutput
-
-
Method Details
-
getHttpChannel
-
getInterceptor
-
setInterceptor
-
isWritten
public boolean isWritten() -
getWritten
public long getWritten() -
reopen
public void reopen() -
acquireWriteBlockingCallback
- Throws:
IOException
-
channelWrite
- Throws:
IOException
-
channelWrite
-
onWriteComplete
-
updateApiState
-
maximizeAggregateSpace
private int maximizeAggregateSpace() -
softClose
public void softClose() -
complete
-
completed
Called to indicate that the request cycle has been completed. -
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-
getBuffer
-
acquireBuffer
-
releaseBuffer
-
isClosed
public boolean isClosed() -
isAsync
public boolean isAsync() -
flush
- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
-
checkWritable
- Throws:
EofException
-
write
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
write
- Throws:
IOException
-
write
- Specified by:
write
in classOutputStream
- Throws:
IOException
-
print
- Overrides:
print
in classjavax.servlet.ServletOutputStream
- Throws:
IOException
-
println
- Overrides:
println
in classjavax.servlet.ServletOutputStream
- Throws:
IOException
-
print
- Throws:
IOException
-
println
- Overrides:
println
in classjavax.servlet.ServletOutputStream
- Throws:
IOException
-
println
- Overrides:
println
in classjavax.servlet.ServletOutputStream
- Throws:
IOException
-
println
- Overrides:
println
in classjavax.servlet.ServletOutputStream
- Throws:
IOException
-
println
- Overrides:
println
in classjavax.servlet.ServletOutputStream
- Throws:
IOException
-
println
- Overrides:
println
in classjavax.servlet.ServletOutputStream
- Throws:
IOException
-
println
- Overrides:
println
in classjavax.servlet.ServletOutputStream
- Throws:
IOException
-
sendContent
Blocking send of whole content.- Parameters:
content
- The whole content to send- Throws:
IOException
- if the send fails
-
sendContent
Blocking send of stream content.- Parameters:
in
- The stream content to send- Throws:
IOException
- if the send fails
-
sendContent
Blocking send of channel content.- Parameters:
in
- The channel content to send- Throws:
IOException
- if the send fails
-
sendContent
Blocking send of HTTP content.- Parameters:
content
- The HTTP content to send- Throws:
IOException
- if the send fails
-
sendContent
Asynchronous send of whole content.- Parameters:
content
- The whole content to sendcallback
- The callback to use to notify success or failure
-
sendContent
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
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
-
sendContent
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
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:
IOException
- if the minimum data rate, when set, is not respected- See Also:
-
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() -
stateString
-
toString
-