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

public Class GzipOutputFilter

extends Object
implements OutputFilter
Class Inheritance
All Implemented Interfaces
org.apache.coyote.http11.OutputFilter, org.apache.coyote.http11.HttpOutputBuffer, org.apache.coyote.OutputBuffer
Imports
java.io.IOException, .OutputStream, java.nio.ByteBuffer, java.util.zip.GZIPOutputStream, org.apache.coyote.Response, org.apache.coyote.http11.HttpOutputBuffer, .OutputFilter, org.apache.juli.logging.Log, .LogFactory, org.apache.tomcat.util.res.StringManager

Gzip output filter.
Author
Remy Maucherat

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class

Field Summary

Modifier and TypeField and Description
protected HttpOutputBuffer
buffer

Next buffer in the pipeline.

protected GZIPOutputStream
compressionStream

Compression output stream.

protected final OutputStream
fakeOutputStream

Fake internal output stream.

protected static final Log
private static final StringManager

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
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
flush()

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

Added to allow flushing to happen for the gzip'ed outputstream

public long
getBytesWritten()

Implements org.apache.coyote.OutputBuffer.getBytesWritten.

Bytes written to the underlying socket.

public void
recycle()

Implements org.apache.coyote.http11.OutputFilter.recycle.

Make the filter ready to process the next request.

public void
setBuffer(HttpOutputBuffer
The next buffer instance
buffer
)

Implements org.apache.coyote.http11.OutputFilter.setBuffer.

Set the next buffer in the filter pipeline.

public void
setResponse(Response
The response to associate with this OutputFilter
response
)

Implements org.apache.coyote.http11.OutputFilter.setResponse.

Some filters need additional parameters from the response.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufferback to summary
protected HttpOutputBuffer buffer

Next buffer in the pipeline.

compressionStreamback to summary
protected GZIPOutputStream compressionStream

Compression output stream.

fakeOutputStreamback to summary
protected final OutputStream fakeOutputStream

Fake internal output stream.

logback to summary
protected static final Log log
smback to summary
private static final StringManager sm

Constructor Detail

GzipOutputFilterback to summary
public GzipOutputFilter()

Method Detail

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
flushback to summary
public void flush() throws IOException

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

Added to allow flushing to happen for the gzip'ed outputstream

Annotations
@Override
Exceptions
IOException:

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

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
recycleback to summary
public void recycle()

Implements org.apache.coyote.http11.OutputFilter.recycle.

Make the filter ready to process the next request.

Annotations
@Override
setBufferback to summary
public void setBuffer(HttpOutputBuffer buffer)

Implements org.apache.coyote.http11.OutputFilter.setBuffer.

Doc from org.apache.coyote.http11.OutputFilter.setBuffer.

Set the next buffer in the filter pipeline.

Parameters
buffer:HttpOutputBuffer

The next buffer instance

Annotations
@Override
setResponseback to summary
public void setResponse(Response response)

Implements org.apache.coyote.http11.OutputFilter.setResponse.

Doc from org.apache.coyote.http11.OutputFilter.setResponse.

Some filters need additional parameters from the response. All the necessary reading can occur in that method, as this method is called after the response header processing is complete.

Parameters
response:Response

The response to associate with this OutputFilter

Annotations
@Override
org.apache.coyote.http11.filters back to summary

protected Class GzipOutputFilter.FakeOutputStream

extends OutputStream
Class Inheritance

Field Summary

Modifier and TypeField and Description
protected final ByteBuffer

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with this stream.

public void
flush()

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Flushes this output stream and forces any buffered output bytes to be written out.

public void
write(int
the byte.
b
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.

public void
write(byte[]
the data.
b
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
len
)

Overrides java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.

Inherited from java.io.OutputStream:
nullOutputStreamwrite

Field Detail

outputChunkback to summary
protected final ByteBuffer outputChunk

Constructor Detail

FakeOutputStreamback to summary
protected FakeOutputStream()

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.OutputStream.close.

Closes this output stream and releases any system resources associated with this stream. The general contract of close is that it closes the output stream. A closed stream cannot perform output operations and cannot be reopened.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
flushback to summary
public void flush() throws IOException

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Doc from java.io.OutputStream.flush.

Flushes this output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination.

If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public void write(int b) throws IOException

Implements abstract java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Parameters
b:int

the byte.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
writeback to summary
public void write(byte[] b, int off, int len) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters
b:byte[]

the data.

off:int

the start offset in the data.

len:int

the number of bytes to write.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.