org.eclipse.jetty.http.gzip
Class AbstractCompressedStream

java.lang.Object
  extended by java.io.OutputStream
      extended by javax.servlet.ServletOutputStream
          extended by org.eclipse.jetty.http.gzip.AbstractCompressedStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public abstract class AbstractCompressedStream
extends javax.servlet.ServletOutputStream

Skeletal implementation of a CompressedStream. This class adds compression features to a ServletOutputStream and takes care of setting response headers, etc. Major work and configuration is done here. Subclasses using different kinds of compression only have to implement the abstract methods doCompress() and setContentEncoding() using the desired compression and setting the appropriate Content-Encoding header string.


Field Summary
protected  ByteArrayOutputStream2 _bOut
           
protected  int _bufferSize
           
protected  boolean _closed
           
protected  java.util.zip.DeflaterOutputStream _compressedOutputStream
           
protected  long _contentLength
           
protected  boolean _doNotCompress
           
protected  int _minCompressSize
           
protected  java.io.OutputStream _out
           
protected  javax.servlet.http.HttpServletRequest _request
           
protected  javax.servlet.http.HttpServletResponse _response
           
 
Constructor Summary
AbstractCompressedStream(java.lang.String encoding, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, long contentLength, int bufferSize, int minCompressSize)
          Instantiates a new compressed stream.
 
Method Summary
 void close()
           
protected abstract  java.util.zip.DeflaterOutputStream createStream()
          Create the stream fitting to the underlying compression type.
 void doCompress()
          Do compress.
 void doNotCompress()
          Do not compress.
 void finish()
          Finish.
 void flush()
           
 java.io.OutputStream getOutputStream()
           
 boolean isClosed()
           
protected  java.io.PrintWriter newWriter(java.io.OutputStream out, java.lang.String encoding)
          Allows derived implementations to replace PrintWriter implementation.
 void resetBuffer()
          Reset buffer.
 void setContentLength(long length)
          Sets the content length.
protected  void setHeader(java.lang.String name, java.lang.String value)
           
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 
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

_request

protected javax.servlet.http.HttpServletRequest _request

_response

protected javax.servlet.http.HttpServletResponse _response

_out

protected java.io.OutputStream _out

_bOut

protected ByteArrayOutputStream2 _bOut

_compressedOutputStream

protected java.util.zip.DeflaterOutputStream _compressedOutputStream

_closed

protected boolean _closed

_bufferSize

protected int _bufferSize

_minCompressSize

protected int _minCompressSize

_contentLength

protected long _contentLength

_doNotCompress

protected boolean _doNotCompress
Constructor Detail

AbstractCompressedStream

public AbstractCompressedStream(java.lang.String encoding,
                                javax.servlet.http.HttpServletRequest request,
                                javax.servlet.http.HttpServletResponse response,
                                long contentLength,
                                int bufferSize,
                                int minCompressSize)
                         throws java.io.IOException
Instantiates a new compressed stream.

Parameters:
request - the request
response - the response
contentLength - the content length
bufferSize - the buffer size
minCompressSize - the min compress size
Throws:
java.io.IOException - Signals that an I/O exception has occurred.
Method Detail

resetBuffer

public void resetBuffer()
Reset buffer.


setContentLength

public void setContentLength(long length)
Sets the content length.

Parameters:
length - the new content length

flush

public void flush()
           throws java.io.IOException
Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException
See Also:
OutputStream.flush()

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException
See Also:
OutputStream.close()

finish

public void finish()
            throws java.io.IOException
Finish.

Throws:
java.io.IOException - Signals that an I/O exception has occurred.

write

public void write(int b)
           throws java.io.IOException
Specified by:
write in class java.io.OutputStream
Throws:
java.io.IOException
See Also:
OutputStream.write(int)

write

public void write(byte[] b)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException
See Also:
OutputStream.write(byte[])

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException
See Also:
OutputStream.write(byte[], int, int)

doCompress

public void doCompress()
                throws java.io.IOException
Do compress.

Throws:
java.io.IOException - Signals that an I/O exception has occurred.

doNotCompress

public void doNotCompress()
                   throws java.io.IOException
Do not compress.

Throws:
java.io.IOException - Signals that an I/O exception has occurred.

getOutputStream

public java.io.OutputStream getOutputStream()
See Also:
org.eclipse.jetty.http.gzip.CompressedStream#getOutputStream()

isClosed

public boolean isClosed()
See Also:
org.eclipse.jetty.http.gzip.CompressedStream#isClosed()

newWriter

protected java.io.PrintWriter newWriter(java.io.OutputStream out,
                                        java.lang.String encoding)
                                 throws java.io.UnsupportedEncodingException
Allows derived implementations to replace PrintWriter implementation.

Throws:
java.io.UnsupportedEncodingException

setHeader

protected void setHeader(java.lang.String name,
                         java.lang.String value)

createStream

protected abstract java.util.zip.DeflaterOutputStream createStream()
                                                            throws java.io.IOException
Create the stream fitting to the underlying compression type.

Throws:
java.io.IOException - Signals that an I/O exception has occurred.


Copyright © 2013. All Rights Reserved.