You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by me...@apache.org on 2009/05/03 15:42:51 UTC

svn commit: r771054 - in /incubator/click/trunk/click: documentation/docs/roadmap-changes.html extras/src/org/apache/click/extras/filter/CompressionResponseStream.java extras/src/org/apache/click/extras/filter/CompressionServletResponseWrapper.java

Author: medgar
Date: Sun May  3 13:42:51 2009
New Revision: 771054

URL: http://svn.apache.org/viewvc?rev=771054&view=rev
Log:
CLK-547

Modified:
    incubator/click/trunk/click/documentation/docs/roadmap-changes.html
    incubator/click/trunk/click/extras/src/org/apache/click/extras/filter/CompressionResponseStream.java
    incubator/click/trunk/click/extras/src/org/apache/click/extras/filter/CompressionServletResponseWrapper.java

Modified: incubator/click/trunk/click/documentation/docs/roadmap-changes.html
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/documentation/docs/roadmap-changes.html?rev=771054&r1=771053&r2=771054&view=diff
==============================================================================
--- incubator/click/trunk/click/documentation/docs/roadmap-changes.html (original)
+++ incubator/click/trunk/click/documentation/docs/roadmap-changes.html Sun May  3 13:42:51 2009
@@ -199,6 +199,11 @@
           [<a target='_blank' href="https://issues.apache.org/jira/browse/CLK-534">534</a>].
       </li>
       <li class="change">
+          Update CompressionServletResponseWrapper and CompressionResponseStream classes to have
+          public visibility to enable use in custom servlet Filters
+          [<a target='_blank' href="https://issues.apache.org/click/browse/CLK-547">547</a>].
+      </li>      
+      <li class="change">
           Deprecated methods: <a href="click-api/org/apache/click/Control.html#getHtmlImports()">Control.getHtmlImports()</a> and
           <a href="click-api/org/apache/click/Page.html#getHtmlImports()">Page.getHtmlImports()</a>.
           These methods have been deprecated in favor of

Modified: incubator/click/trunk/click/extras/src/org/apache/click/extras/filter/CompressionResponseStream.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/extras/src/org/apache/click/extras/filter/CompressionResponseStream.java?rev=771054&r1=771053&r2=771054&view=diff
==============================================================================
--- incubator/click/trunk/click/extras/src/org/apache/click/extras/filter/CompressionResponseStream.java (original)
+++ incubator/click/trunk/click/extras/src/org/apache/click/extras/filter/CompressionResponseStream.java Sun May  3 13:42:51 2009
@@ -33,7 +33,7 @@
  * @author Dmitri Valdin
  * @version Revision: 1.3 , Date: 2004/03/18 16:40:28
  */
-class CompressionResponseStream extends ServletOutputStream {
+public class CompressionResponseStream extends ServletOutputStream {
 
     // ----------------------------------------------------------- Constructors
 
@@ -41,6 +41,7 @@
      * Construct a servlet output stream associated with the specified Response.
      *
      * @param response The associated response
+     * @throws IOException if an IO error occurs reading the response stream
      */
     public CompressionResponseStream(HttpServletResponse response)
         throws IOException {
@@ -49,7 +50,6 @@
         closed = false;
         this.response = response;
         this.output = response.getOutputStream();
-
     }
 
     // ----------------------------------------------------- Instance Variables
@@ -60,9 +60,7 @@
      */
     protected int compressionThreshold = 0;
 
-    /**
-     * Debug level.
-     */
+    /** Debug level. */
     private int debug = 0;
 
     /**
@@ -70,9 +68,7 @@
      */
     protected byte[] buffer = null;
 
-    /**
-     * The number of data bytes currently in the buffer.
-     */
+    /** The number of data bytes currently in the buffer. */
     protected int bufferCount = 0;
 
     /**
@@ -80,9 +76,7 @@
      */
     protected GZIPOutputStream gzipstream = null;
 
-    /**
-     * Has this stream been closed?
-     */
+    /** Has this stream been closed? */
     protected boolean closed = false;
 
     /**
@@ -105,6 +99,8 @@
 
     /**
      * Set the compressionThreshold number and create buffer for this size.
+     *
+     * @param threshold the compression threshold in bytes
      */
     protected void setBuffer(int threshold) {
         compressionThreshold = threshold;
@@ -114,6 +110,8 @@
     /**
      * Close this output stream, causing any buffered data to be flushed and
      * any further output data to throw an IOException.
+     *
+     * @throws IOException if an error occurs closing the response
      */
     public void close() throws IOException {
 
@@ -139,12 +137,13 @@
 
         output.close();
         closed = true;
-
     }
 
     /**
      * Flush any buffered data for this output stream, which also causes the
      * response to be committed.
+     *
+     * @throws IOException if an error occurs flushing the gzip stream
      */
     public void flush() throws IOException {
 
@@ -155,16 +154,19 @@
         if (gzipstream != null) {
             gzipstream.flush();
         }
-
     }
 
+    /**
+     * Flush the buffer to the gzip stream.
+     *
+     * @throws IOException if an error occurs flushing the buffer
+     */
     public void flushToGZip() throws IOException {
 
         if (bufferCount > 0) {
             writeToGZip(buffer, 0, bufferCount);
             bufferCount = 0;
         }
-
     }
 
     /**
@@ -185,7 +187,6 @@
         }
 
         buffer[bufferCount++] = (byte) b;
-
     }
 
     /**
@@ -193,7 +194,6 @@
      * to our output stream.
      *
      * @param b The byte array to be written
-     *
      * @exception IOException if an input/output error occurs
      */
     public void write(byte b[]) throws IOException {
@@ -207,7 +207,6 @@
      * @param b The byte array containing the bytes to be written
      * @param off Zero-relative starting offset of the bytes to be written
      * @param len The number of bytes to be written
-     *
      * @exception IOException if an input/output error occurs
      */
     public void write(byte b[], int off, int len) throws IOException {
@@ -241,20 +240,32 @@
         writeToGZip(b, off, len);
     }
 
+
+    /**
+     * Writes array of bytes to the compressed output stream. This method
+     * will block until all the bytes are written.
+     *
+     * @param b the data to be written
+     * @param off the start offset of the data
+     * @param len the length of the data
+     * @exception IOException If an I/O error has occurred.
+     */
     public void writeToGZip(byte b[], int off, int len) throws IOException {
 
         if (gzipstream == null) {
             response.addHeader("Content-Encoding", "gzip");
             gzipstream = new GZIPOutputStream(output);
         }
-        gzipstream.write(b, off, len);
 
+        gzipstream.write(b, off, len);
     }
 
     // -------------------------------------------------------- Package Methods
 
     /**
      * Has this response stream been closed?
+     *
+     * @return true if the response stream has been closed
      */
     public boolean closed() {
         return (this.closed);

Modified: incubator/click/trunk/click/extras/src/org/apache/click/extras/filter/CompressionServletResponseWrapper.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/extras/src/org/apache/click/extras/filter/CompressionServletResponseWrapper.java?rev=771054&r1=771053&r2=771054&view=diff
==============================================================================
--- incubator/click/trunk/click/extras/src/org/apache/click/extras/filter/CompressionServletResponseWrapper.java (original)
+++ incubator/click/trunk/click/extras/src/org/apache/click/extras/filter/CompressionServletResponseWrapper.java Sun May  3 13:42:51 2009
@@ -35,15 +35,16 @@
  * @author Dmitri Valdin
  * @version Revision: 1.3, Date: 2004/03/18 16:40:28
  */
-class CompressionServletResponseWrapper extends HttpServletResponseWrapper {
+public class CompressionServletResponseWrapper extends HttpServletResponseWrapper {
 
     // ----------------------------------------------------- Constructor
 
     /**
      * Calls the parent constructor which creates a ServletResponse adaptor
      * wrapping the given response object.
+     *
+     * @param response the servlet response to wrap
      */
-
     public CompressionServletResponseWrapper(HttpServletResponse response) {
         super(response);
         origResponse = response;
@@ -51,14 +52,10 @@
 
     // ----------------------------------------------------- Instance Variables
 
-    /**
-     * Original response.
-     */
+    /** Original response. */
     protected HttpServletResponse origResponse = null;
 
-    /**
-     * Descriptive information about this Response implementation.
-     */
+    /** Descriptive information about this Response implementation. */
     protected static final String INFO = "CompressionServletResponseWrapper";
 
     /**
@@ -73,44 +70,41 @@
      */
     protected PrintWriter writer = null;
 
-    /**
-     * The threshold number to compress.
-     */
+    /** The threshold number to compress. */
     protected int threshold = 0;
 
-    /**
-     * Debug level.
-     */
+    /** Debug level. */
     private int debug = 0;
 
-    /**
-     * Content type.
-     */
+    /** Content type. */
     protected String contentType = null;
 
     // --------------------------------------------------------- Public Methods
 
     /**
      * Set content type.
+     *
+     * @param contentType the response content type
      */
     public void setContentType(String contentType) {
         this.contentType = contentType;
         origResponse.setContentType(contentType);
     }
 
-
     /**
-     * Set threshold number.
+     * Set threshold the compression threshold in bytes.
+     *
+     * @param threshold the compression threshold in bytes
      */
     public void setCompressionThreshold(int threshold) {
         this.threshold = threshold;
     }
 
-
     /**
      * Create and return a ServletOutputStream to write the content
      * associated with this Response.
      *
+     * @return a new compressed servlet output stream
      * @exception IOException if an input/output error occurs
      */
     public ServletOutputStream createOutputStream() throws IOException {
@@ -157,6 +151,7 @@
     /**
      * Return the servlet output stream associated with this Response.
      *
+     * @return the servlet output stream associated with this response
      * @exception IllegalStateException if <code>getWriter</code> has
      *  already been called for this response
      * @exception IOException if an input/output error occurs
@@ -174,12 +169,12 @@
         }
 
         return (stream);
-
     }
 
     /**
      * Return the writer associated with this Response.
      *
+     * @return the servlet print writer
      * @exception IllegalStateException if <code>getOutputStream</code> has
      *  already been called for this response
      * @exception IOException if an input/output error occurs
@@ -212,21 +207,38 @@
         }
 
         return (writer);
-
     }
 
+    /**
+     * Set the content length. This method does nothing.
+     *
+     * @param length the content length
+     */
     public void setContentLength(int length) {
     }
 
+    /**
+     * Set the int value in the header.
+     *
+     * @param header the response header
+     * @param value the int value
+     */
     public void setIntHeader(String header, int value) {
         if (!"Content-Length".equals(header)) {
             super.setIntHeader(header, value);
         }
     }
 
+    /**
+     * Set the string value in the header.
+     *
+     * @param header the response header
+     * @param value the string value
+     */
     public void setHeader(String header, String value) {
         if (!"Content-Length".equals(header)) {
             super.setHeader(header, value);
         }
     }
+
 }