Package org.apache.coyote.http11
Class Http11OutputBuffer
- java.lang.Object
- 
- org.apache.coyote.http11.Http11OutputBuffer
 
- 
- All Implemented Interfaces:
- HttpOutputBuffer,- OutputBuffer
 
 public class Http11OutputBuffer extends java.lang.Object implements HttpOutputBuffer Provides buffering for the HTTP headers (allowing responses to be reset before they have been committed) and the link to the Socket for writing the headers (once committed) and the response body. Note that buffering of the response body happens at a higher level.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description protected classHttp11OutputBuffer.SocketOutputBufferThis class is an output buffer which will write data to a socket.
 - 
Field SummaryFields Modifier and Type Field Description protected OutputFilter[]activeFiltersActive filters for the current request.protected longbyteCountBytes written to client for the current requestprotected OutputFilter[]filterLibraryFilter library for processing the response body.protected java.nio.ByteBufferheaderBufferThe buffer used for header composition.protected intlastActiveFilterIndex of the last active filter.protected HttpOutputBufferoutputStreamOutputBufferUnderlying output buffer.protected ResponseresponseAssociated Coyote response.protected booleanresponseFinishedFinished flag.protected static StringManagersmThe string manager for this package.protected SocketWrapperBase<?>socketWrapperWrapper for socket where data will be written to.
 - 
Constructor SummaryConstructors Modifier Constructor Description protectedHttp11OutputBuffer(Response response, int headerBufferSize)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddActiveFilter(OutputFilter filter)Add an output filter to the active filters for the current response.voidaddFilter(OutputFilter filter)Add an output filter to the filter library.protected voidcommit()Commit the response.intdoWrite(java.nio.ByteBuffer chunk)Write the given data to the response.voidend()Finish writing the current response.voidendHeaders()End the header block.voidflush()Flush the response.protected booleanflushBuffer(boolean block)Writes any remaining buffered data.longgetBytesWritten()Bytes written to the underlying socket.OutputFilter[]getFilters()Get filters.booleanhasDataToWrite()voidinit(SocketWrapperBase<?> socketWrapper)protected booleanisBlocking()Is standard Servlet blocking IO being used for output?protected booleanisReady()voidnextRequest()End processing of current HTTP request.voidrecycle()Recycle the output buffer.voidregisterWriteInterest()voidsendAck()voidsendHeader(MessageBytes name, MessageBytes value)Send a header.voidsendStatus()Send the response status line.voidwrite(byte[] b)This method will write the contents of the specified byte buffer to the output stream, without filtering.
 
- 
- 
- 
Field Detail- 
smprotected static final StringManager sm The string manager for this package.
 - 
responseprotected final Response response Associated Coyote response.
 - 
responseFinishedprotected boolean responseFinished Finished flag.
 - 
headerBufferprotected final java.nio.ByteBuffer headerBuffer The buffer used for header composition.
 - 
filterLibraryprotected OutputFilter[] filterLibrary Filter library for processing the response body.
 - 
activeFiltersprotected OutputFilter[] activeFilters Active filters for the current request.
 - 
lastActiveFilterprotected int lastActiveFilter Index of the last active filter.
 - 
outputStreamOutputBufferprotected HttpOutputBuffer outputStreamOutputBuffer Underlying output buffer.
 - 
socketWrapperprotected SocketWrapperBase<?> socketWrapper Wrapper for socket where data will be written to.
 - 
byteCountprotected long byteCount Bytes written to client for the current request
 
- 
 - 
Constructor Detail- 
Http11OutputBufferprotected Http11OutputBuffer(Response response, int headerBufferSize) 
 
- 
 - 
Method Detail- 
addFilterpublic void addFilter(OutputFilter filter) Add an output filter to the filter library. Note that calling this method resets the currently active filters to none.- Parameters:
- filter- The filter to add
 
 - 
getFilterspublic OutputFilter[] getFilters() Get filters.- Returns:
- The current filter library containing all possible filters
 
 - 
addActiveFilterpublic void addActiveFilter(OutputFilter filter) Add an output filter to the active filters for the current response.The filter does not have to be present in getFilters().A filter can only be added to a response once. If the filter has already been added to this response then this method will be a NO-OP. - Parameters:
- filter- The filter to add
 
 - 
doWritepublic int doWrite(java.nio.ByteBuffer chunk) throws java.io.IOExceptionDescription copied from interface:OutputBufferWrite the given data to the response. The caller owns the chunks.- Specified by:
- doWritein interface- OutputBuffer
- Parameters:
- chunk- data to write
- Returns:
- The number of bytes written which may be less than available in the input chunk
- Throws:
- java.io.IOException- an underlying I/O error occurred
 
 - 
getBytesWrittenpublic long getBytesWritten() Description copied from interface:OutputBufferBytes written to the underlying socket. This includes the effects of chunking, compression, etc.- Specified by:
- getBytesWrittenin interface- OutputBuffer
- Returns:
- Bytes written for the current request
 
 - 
flushpublic void flush() throws java.io.IOExceptionFlush the response.- Specified by:
- flushin interface- HttpOutputBuffer
- Throws:
- java.io.IOException- an underlying I/O error occurred
 
 - 
endpublic void end() throws java.io.IOExceptionDescription copied from interface:HttpOutputBufferFinish writing the current response. It is acceptable to write extra bytes usingOutputBuffer.doWrite(java.nio.ByteBuffer)during the execution of this method.- Specified by:
- endin interface- HttpOutputBuffer
- Throws:
- java.io.IOException- If an I/O error occurs while writing to the client
 
 - 
recyclepublic void recycle() Recycle the output buffer. This should be called when closing the connection.
 - 
nextRequestpublic void nextRequest() End processing of current HTTP request. Note: All bytes of the current request should have been already consumed. This method only resets all the pointers so that we are ready to parse the next HTTP request.
 - 
initpublic void init(SocketWrapperBase<?> socketWrapper) 
 - 
sendAckpublic void sendAck() throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
commitprotected void commit() throws java.io.IOExceptionCommit the response.- Throws:
- java.io.IOException- an underlying I/O error occurred
 
 - 
sendStatuspublic void sendStatus() Send the response status line.
 - 
sendHeaderpublic void sendHeader(MessageBytes name, MessageBytes value) Send a header.- Parameters:
- name- Header name
- value- Header value
 
 - 
endHeaderspublic void endHeaders() End the header block.
 - 
writepublic void write(byte[] b) This method will write the contents of the specified byte buffer to the output stream, without filtering. This method is meant to be used to write the response header.- Parameters:
- b- data to be written
 
 - 
flushBufferprotected boolean flushBuffer(boolean block) throws java.io.IOExceptionWrites any remaining buffered data.- Parameters:
- block- Should this method block until the buffer is empty
- Returns:
- trueif data remains in the buffer (which can only happen in non-blocking mode) else- false.
- Throws:
- java.io.IOException- Error writing data
 
 - 
isBlockingprotected final boolean isBlocking() Is standard Servlet blocking IO being used for output?- Returns:
- trueif this is blocking IO
 
 - 
isReadyprotected final boolean isReady() 
 - 
hasDataToWritepublic boolean hasDataToWrite() 
 - 
registerWriteInterestpublic void registerWriteInterest() 
 
- 
 
-