|
Rakesh API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.OutputStream
javax.servlet.ServletOutputStream
org.rakeshv.filters.CompressionResponseStream
public class CompressionResponseStream
A sub-class of ServletOutputStream that is used to
compress the response sent by the server to a client request. The
only compression method supported are those that are available in the
java.util.zip package.
© Copyright 2003, Rakesh Vidyadharan
| Field Summary | |
|---|---|
protected boolean |
closed
Has this stream been closed? |
protected int |
compressionType
The type of compression algorithm to use. |
protected java.util.zip.DeflaterOutputStream |
deflaterStream
The underlying gzip output stream to which we should write data. |
protected javax.servlet.ServletOutputStream |
output
The underlying servlet output stream to which we should write data. |
protected javax.servlet.http.HttpServletResponse |
response
The response with which this servlet output stream is associated. |
| Constructor Summary | |
|---|---|
CompressionResponseStream(javax.servlet.http.HttpServletResponse response)
Initialise a new instance of this class with the specified servlet response. |
|
| Method Summary | |
|---|---|
void |
close()
Close this output stream, causing any buffered data to be flushed and any further output data to throw an IOException. |
protected void |
createDeflaterStream()
Initialise the deflaterStream with the appropriate type
of compressed output stream based upon the value in the
compressionType instance variable. |
void |
finish()
Finishes writing compressed data to the output stream without closing the underlying stream. |
void |
flush()
Flushes the underlying servlet output stream. |
boolean |
getClosed()
Returns closed. |
int |
getCompressionType()
Returns compressionType. |
void |
setCompressionType(int compressionType)
Set compressionType. |
void |
write(byte[] buf)
Over-ridden to ensure that the method just invokes the write( byte[], int, int ) method. |
void |
write(byte[] buf,
int off,
int len)
Over-ridden form of the method. |
void |
write(int value)
Over-ridden form of the method. |
protected void |
writeToDeflater(byte[] buf,
int off,
int len)
Writes the date from the specified byte array to the deflaterStream. |
protected void |
writeToDeflater(int value)
Write the specified value to the deflaterStream. |
| Methods inherited from class javax.servlet.ServletOutputStream |
|---|
print, print, print, print, print, print, print, println, println, println, println, println, println, println, println |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected java.util.zip.DeflaterOutputStream deflaterStream
protected boolean closed
protected javax.servlet.http.HttpServletResponse response
protected javax.servlet.ServletOutputStream output
protected int compressionType
Deflate, GZIP, Zip.
| Constructor Detail |
|---|
public CompressionResponseStream(javax.servlet.http.HttpServletResponse response)
throws java.io.IOException
response - The response to which the contents are to be
sent.
java.io.IOException| Method Detail |
|---|
public void write(int value)
throws java.io.IOException
deflaterStream if the stream has not been closed. Uses
the writeToDeflater( int ) method to write the specified
value to the deflaterStream.
write in class java.io.OutputStreamvalue - - The integer value that is being written.
java.io.IOException - - If the stream has already been closed.
protected void writeToDeflater(int value)
throws java.io.IOException
deflaterStream. Checks
to ensure that the deflaterStream has been created, and
if not, then creates the appropriate instance of the deflaterStream using the compressionType value.
value - - The value to write.
java.io.IOException - - If errors are encountered while trying to
write to the stream.
public void write(byte[] buf)
throws java.io.IOException
write( byte[], int, int ) method.
write in class java.io.OutputStreambuf - - The byte buffer from which the data is to
read and written to the deflaterStream.
java.io.IOException - - If errors are encountered while writing
to the stream.
public void write(byte[] buf,
int off,
int len)
throws java.io.IOException
byte array
to the deflaterStream using writeToDeflater( byte[], int, int).
write in class java.io.OutputStreambuf - - The byte buffer from which the data is to
read and written to the deflaterStream.off - - The offset from the start of the buffer from
which to start reading data.len - - The length of data that is to be read from the
array.
java.io.IOException - - If errors are encountered while writing
to the stream.
protected void writeToDeflater(byte[] buf,
int off,
int len)
throws java.io.IOException
deflaterStream. Checks to ensure that the deflaterStream has been created, and if not, then it creates
the appropriate instance of the deflaterStream based
upon the value of compressionType.
buf - - The byte buffer from which the data is to
read and written to the deflaterStream.off - - The offset from the start of the buffer from
which to start reading data.len - - The length of data that is to be read from the
array.
java.io.IOException - - If errors are encountered while writing
to the stream.
protected void createDeflaterStream()
throws java.io.IOException
deflaterStream with the appropriate type
of compressed output stream based upon the value in the
compressionType instance variable. If the value of
compressionType does not match one of the following,
then Deflate compression is used.
Note: If zip compression is requested, then
the response will contain a ZipEntry object that
contains the data as required by the Zip format.
The file name for the ZipEntry object
is arbitrarily set as the value of System.currentTimeMillis()
java.io.IOException - - If errors are encountered while creating
the stream, or setting its header.
public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in class java.io.OutputStreamjava.io.IOException - - If the stream has already been closed.
public void finish()
throws java.io.IOException
java.io.IOException - - If errors are encountered while writing
to the stream. An exception will be thrown if this method is
invoked after the stream has been closed.
public void flush()
throws java.io.IOException
flush in interface java.io.Flushableflush in class java.io.OutputStreamjava.io.IOException - - If the stream has already been closed.public final boolean getClosed()
closed.
public final int getCompressionType()
compressionType.
public final void setCompressionType(int compressionType)
compressionType.
compressionType - - The value to set.
|
Rakesh API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||