Top Description Inners Fields Constructors Methods
org.apache.coyote.http11

public Class Http11OutputBuffer

extends Object
implements HttpOutputBuffer
Class Inheritance
All Implemented Interfaces
org.apache.coyote.http11.HttpOutputBuffer, org.apache.coyote.OutputBuffer
Imports
java.io.IOException, java.nio.ByteBuffer, java.util.Arrays, org.apache.coyote.ActionCode, .CloseNowException, .Response, org.apache.tomcat.util.buf.ByteChunk, .MessageBytes, org.apache.tomcat.util.net.SocketWrapperBase, org.apache.tomcat.util.res.StringManager

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 and Inner Type Summary

Modifier and TypeClass and Description
protected class
Http11OutputBuffer.SocketOutputBuffer

This class is an output buffer which will write data to a socket.

Field Summary

Modifier and TypeField and Description
private volatile boolean
protected OutputFilter[]
activeFilters

Active filters for the current request.

protected long
byteCount

Bytes written to client for the current request

protected OutputFilter[]
filterLibrary

Filter library for processing the response body.

protected final ByteBuffer
headerBuffer

The buffer used for header composition.

protected int
lastActiveFilter

Index of the last active filter.

protected HttpOutputBuffer
outputStreamOutputBuffer

Underlying output buffer.

protected final Response
response

Associated Coyote response.

protected boolean
responseFinished

Finished flag.

protected static final StringManager
sm

The string manager for this package.

protected SocketWrapperBase<?>
socketWrapper

Wrapper for socket where data will be written to.

Constructor Summary

AccessConstructor and Description
protected
Http11OutputBuffer(Response response, int headerBufferSize)

Method Summary

Modifier and TypeMethod and Description
public void
addActiveFilter(OutputFilter
The filter to add
filter
)

Add an output filter to the active filters for the current response.

public void
addFilter(OutputFilter
The filter to add
filter
)

Add an output filter to the filter library.

private void
checkLengthBeforeWrite(int length)

Checks to see if there is enough space in the buffer to write the requested number of bytes.

protected void
commit()

Commit the response.

public int
doWrite(ByteBuffer
data to write
chunk
)

Implements org.apache.coyote.OutputBuffer.doWrite.

Write the given data to the response.

public void
end()

Implements org.apache.coyote.http11.HttpOutputBuffer.end.

Finish writing the current response.

public void
endHeaders()

End the header block.

public void
flush()

Implements org.apache.coyote.http11.HttpOutputBuffer.flush.

Flush the response.

protected boolean

Returns:

true if data remains in the buffer (which can only happen in non-blocking mode) else false.
flushBuffer
(boolean
Should this method block until the buffer is empty
block
)

Writes any remaining buffered data.

public long
getBytesWritten()

Implements org.apache.coyote.OutputBuffer.getBytesWritten.

Bytes written to the underlying socket.

public OutputFilter[]

Returns:

The current filter library containing all possible filters
getFilters
()

Get filters.

public boolean
public void
init(SocketWrapperBase<?> socketWrapper)

protected final boolean

Returns:

true if this is blocking IO
isBlocking
()

Is standard Servlet blocking IO being used for output?

pack-priv boolean
protected final boolean
public void
nextRequest()

End processing of current HTTP request.

public void
recycle()

Recycle the output buffer.

public void
pack-priv void
resetHeaderBuffer()

Reset the header buffer if an error occurs during the writing of the headers so the error response can be written.

public void
public void
sendHeader(MessageBytes
Header name
name
,
MessageBytes
Header value
value
)

Send a header.

public void
sendStatus()

Send the response status line.

private void
write(MessageBytes
data to be written
mb
)

This method will write the contents of the specified message bytes buffer to the output stream, without filtering.

private void
write(ByteChunk
data to be written
bc
)

This method will write the contents of the specified byte chunk to the output stream, without filtering.

public void
write(byte[]
data to be written
b
)

This method will write the contents of the specified byte buffer to the output stream, without filtering.

private void
write(int
data to be written
value
)

This method will write the specified integer to the output stream.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ackSentback to summary
private volatile boolean ackSent
activeFiltersback to summary
protected OutputFilter[] activeFilters

Active filters for the current request.

byteCountback to summary
protected long byteCount

Bytes written to client for the current request

filterLibraryback to summary
protected OutputFilter[] filterLibrary

Filter library for processing the response body.

headerBufferback to summary
protected final ByteBuffer headerBuffer

The buffer used for header composition.

lastActiveFilterback to summary
protected int lastActiveFilter

Index of the last active filter.

outputStreamOutputBufferback to summary
protected HttpOutputBuffer outputStreamOutputBuffer

Underlying output buffer.

responseback to summary
protected final Response response

Associated Coyote response.

responseFinishedback to summary
protected boolean responseFinished

Finished flag.

smback to summary
protected static final StringManager sm

The string manager for this package.

socketWrapperback to summary
protected SocketWrapperBase<?> socketWrapper

Wrapper for socket where data will be written to.

Constructor Detail

Http11OutputBufferback to summary
protected Http11OutputBuffer(Response response, int headerBufferSize)

Method Detail

addActiveFilterback to summary
public 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:OutputFilter

The filter to add

addFilterback to summary
public 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:OutputFilter

The filter to add

checkLengthBeforeWriteback to summary
private void checkLengthBeforeWrite(int length)

Checks to see if there is enough space in the buffer to write the requested number of bytes.

commitback to summary
protected void commit() throws IOException

Commit the response.

Exceptions
IOException:
an underlying I/O error occurred
doWriteback to summary
public int doWrite(ByteBuffer chunk) throws IOException

Implements org.apache.coyote.OutputBuffer.doWrite.

Doc from org.apache.coyote.OutputBuffer.doWrite.

Write the given data to the response. The caller owns the chunks.

Parameters
chunk:ByteBuffer

data to write

Returns:int

The number of bytes written which may be less than available in the input chunk

Annotations
@Override
Exceptions
IOException:
an underlying I/O error occurred
endback to summary
public void end() throws IOException

Implements org.apache.coyote.http11.HttpOutputBuffer.end.

Doc from org.apache.coyote.http11.HttpOutputBuffer.end.

Finish writing the current response. It is acceptable to write extra bytes using doWrite(java.nio.ByteBuffer) during the execution of this method.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs while writing to the client
endHeadersback to summary
public void endHeaders()

End the header block.

flushback to summary
public void flush() throws IOException

Implements org.apache.coyote.http11.HttpOutputBuffer.flush.

Flush the response.

Annotations
@Override
Exceptions
IOException:
an underlying I/O error occurred
flushBufferback to summary
protected boolean flushBuffer(boolean block) throws IOException

Writes any remaining buffered data.

Parameters
block:boolean

Should this method block until the buffer is empty

Returns:boolean

true if data remains in the buffer (which can only happen in non-blocking mode) else false.

Exceptions
IOException:
Error writing data
getBytesWrittenback to summary
public long getBytesWritten()

Implements org.apache.coyote.OutputBuffer.getBytesWritten.

Doc from org.apache.coyote.OutputBuffer.getBytesWritten.

Bytes written to the underlying socket. This includes the effects of chunking, compression, etc.

Returns:long

Bytes written for the current request

Annotations
@Override
getFiltersback to summary
public OutputFilter[] getFilters()

Get filters.

Returns:OutputFilter[]

The current filter library containing all possible filters

hasDataToWriteback to summary
public boolean hasDataToWrite()
initback to summary
public void init(SocketWrapperBase<?> socketWrapper)
isBlockingback to summary
protected final boolean isBlocking()

Is standard Servlet blocking IO being used for output?

Returns:boolean

true if this is blocking IO

isChunkingback to summary
pack-priv boolean isChunking()
isReadyback to summary
protected final boolean isReady()
nextRequestback to summary
public 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.

recycleback to summary
public void recycle()

Recycle the output buffer. This should be called when closing the connection.

registerWriteInterestback to summary
public void registerWriteInterest()
resetHeaderBufferback to summary
pack-priv void resetHeaderBuffer()

Reset the header buffer if an error occurs during the writing of the headers so the error response can be written.

sendAckback to summary
public void sendAck() throws IOException
sendHeaderback to summary
public void sendHeader(MessageBytes name, MessageBytes value)

Send a header.

Parameters
name:MessageBytes

Header name

value:MessageBytes

Header value

sendStatusback to summary
public void sendStatus()

Send the response status line.

writeback to summary
private void write(MessageBytes mb)

This method will write the contents of the specified message bytes buffer to the output stream, without filtering. This method is meant to be used to write the response header.

Parameters
mb:MessageBytes

data to be written

writeback to summary
private void write(ByteChunk bc)

This method will write the contents of the specified byte chunk to the output stream, without filtering. This method is meant to be used to write the response header.

Parameters
bc:ByteChunk

data to be written

writeback to summary
public 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:byte[]

data to be written

writeback to summary
private void write(int value)

This method will write the specified integer to the output stream. This method is meant to be used to write the response header.

Parameters
value:int

data to be written

org.apache.coyote.http11 back to summary

protected Class Http11OutputBuffer.SocketOutputBuffer

extends Object
implements HttpOutputBuffer
Class Inheritance
  • java.lang.Object
  • org.apache.coyote.http11.Http11OutputBuffer.SocketOutputBuffer
All Implemented Interfaces
org.apache.coyote.http11.HttpOutputBuffer, org.apache.coyote.OutputBuffer

This class is an output buffer which will write data to a socket.

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public int
doWrite(ByteBuffer
data to write
chunk
)

Implements org.apache.coyote.OutputBuffer.doWrite.

Write chunk.

public void
end()

Implements org.apache.coyote.http11.HttpOutputBuffer.end.

Finish writing the current response.

public void
flush()

Implements org.apache.coyote.http11.HttpOutputBuffer.flush.

Flushes any unwritten data to the client.

public long
getBytesWritten()

Implements org.apache.coyote.OutputBuffer.getBytesWritten.

Bytes written to the underlying socket.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

SocketOutputBufferback to summary
protected SocketOutputBuffer()

Method Detail

doWriteback to summary
public int doWrite(ByteBuffer chunk) throws IOException

Implements org.apache.coyote.OutputBuffer.doWrite.

Write chunk.

Parameters
chunk:ByteBuffer

Doc from org.apache.coyote.OutputBuffer.doWrite.

data to write

Returns:int

Doc from org.apache.coyote.OutputBuffer.doWrite.

The number of bytes written which may be less than available in the input chunk

Annotations
@Override
Exceptions
IOException:

Doc from org.apache.coyote.OutputBuffer.doWrite.

an underlying I/O error occurred

endback to summary
public void end() throws IOException

Implements org.apache.coyote.http11.HttpOutputBuffer.end.

Doc from org.apache.coyote.http11.HttpOutputBuffer.end.

Finish writing the current response. It is acceptable to write extra bytes using doWrite(java.nio.ByteBuffer) during the execution of this method.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs while writing to the client
flushback to summary
public void flush() throws IOException

Implements org.apache.coyote.http11.HttpOutputBuffer.flush.

Doc from org.apache.coyote.http11.HttpOutputBuffer.flush.

Flushes any unwritten data to the client.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs while flushing
getBytesWrittenback to summary
public long getBytesWritten()

Implements org.apache.coyote.OutputBuffer.getBytesWritten.

Doc from org.apache.coyote.OutputBuffer.getBytesWritten.

Bytes written to the underlying socket. This includes the effects of chunking, compression, etc.

Returns:long

Bytes written for the current request

Annotations
@Override