tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amy...@apache.org
Subject cvs commit: jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters CompressionFilter.java CompressionFilterTestServlet.java CompressionResponseStream.java CompressionServletResponseWrapper.java
Date Thu, 06 Sep 2001 04:18:54 GMT
amyroh      01/09/05 21:18:54

  Modified:    webapps/examples/WEB-INF/classes/compressionFilters
                        CompressionFilter.java
                        CompressionFilterTestServlet.java
                        CompressionResponseStream.java
                        CompressionServletResponseWrapper.java
  Log:
  Fixed closing before flush, format, and unnecessary commit.
  
  Revision  Changes    Path
  1.4       +106 -98   jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilter.java
  
  Index: CompressionFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- CompressionFilter.java	2001/03/22 17:49:24	1.3
  +++ CompressionFilter.java	2001/09/06 04:18:53	1.4
  @@ -1,8 +1,8 @@
   /*
    * CompressionFilter.java
  - * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilter.java,v
1.3 2001/03/22 17:49:24 amyroh Exp $
  - * $Revision: 1.3 $
  - * $Date: 2001/03/22 17:49:24 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilter.java,v
1.4 2001/09/06 04:18:53 amyroh Exp $
  + * $Revision: 1.4 $
  + * $Date: 2001/09/06 04:18:53 $
    *
    * ====================================================================
    *
  @@ -80,116 +80,124 @@
    * the ServletResponse if it is bigger than a threshold.
    *
    * @author Amy Roh
  - * @version $Revision: 1.3 $, $Date: 2001/03/22 17:49:24 $
  + * @version $Revision: 1.4 $, $Date: 2001/09/06 04:18:53 $
    */
   
   public class CompressionFilter implements Filter{
   
  -  /**
  -   * The filter configuration object we are associated with.  If this value
  -   * is null, this filter instance is not currently configured.
  -   */
  -  private FilterConfig config = null;
  -
  -  /**
  -   * The threshold number to compress
  -   */
  -  protected int compressionThreshold;
  -
  -  /**
  -   * Debug level for this filter
  -   */
  -  private int debug = 0;
  -
  -  /**
  -   * Place this filter into service.
  -   *
  -   * @param filterConfig The filter configuration object
  -   */
  -
  -  public void init(FilterConfig filterConfig) {
  -
  -    config = filterConfig;
  -    if (filterConfig != null) {
  -      String str = filterConfig.getInitParameter("compressionThreshold");
  -      if (str!=null) {
  -        compressionThreshold = Integer.parseInt(str);
  -      }
  -      else compressionThreshold = 0;
  -      String value = filterConfig.getInitParameter("debug");
  -      if (value!=null) {
  -	      debug = Integer.parseInt(value);
  -      }
  -      else debug = 0;
  -    } else {
  -      compressionThreshold = 0;
  -    }
  +    /**
  +     * The filter configuration object we are associated with.  If this value
  +     * is null, this filter instance is not currently configured.
  +     */
  +    private FilterConfig config = null;
  +
  +    /**
  +     * The threshold number to compress
  +     */
  +    protected int compressionThreshold;
  +
  +    /**
  +     * Debug level for this filter
  +     */
  +    private int debug = 0;
  +
  +    /**
  +     * Place this filter into service.
  +     *
  +     * @param filterConfig The filter configuration object
  +     */
  +
  +    public void init(FilterConfig filterConfig) {
  +
  +        config = filterConfig;
  +        if (filterConfig != null) {
  +            String str = filterConfig.getInitParameter("compressionThreshold");
  +            if (str!=null) {
  +                compressionThreshold = Integer.parseInt(str);
  +            } else {
  +                compressionThreshold = 0;
  +            }
  +            String value = filterConfig.getInitParameter("debug");
  +            if (value!=null) {
  +                debug = Integer.parseInt(value);
  +            } else {
  +                debug = 0;
  +            }
  +        } else {
  +            compressionThreshold = 0;
  +        }
   
  -  }
  +    }
   
  -  /**
  -   * Take this filter out of service.
  -   */
  +    /**
  +    * Take this filter out of service.
  +    */
  +    public void destroy() {
   
  -  public void destroy() {
  +        this.config = null;
   
  -    this.config = null;
  +    }
   
  -  }
  +    /**
  +     * The <code>doFilter</code> method of the Filter is called by the container
  +     * each time a request/response pair is passed through the chain due
  +     * to a client request for a resource at the end of the chain.
  +     * The FilterChain passed into this method allows the Filter to pass on the
  +     * request and response to the next entity in the chain.<p>
  +     * This method first examines the request to check whether the client support
  +     * compression. <br>
  +     * It simply just pass the request and response if there is no support for
  +     * compression.<br>
  +     * If the compression support is available, it creates a
  +     * CompressionServletResponseWrapper object which compresses the content and
  +     * modifies the header if the content length is big enough.
  +     * It then invokes the next entity in the chain using the FilterChain object
  +     * (<code>chain.doFilter()</code>), <br>
  +     **/
   
  +    public void doFilter ( ServletRequest request, ServletResponse response,
  +                        FilterChain chain ) throws IOException, ServletException {
   
  - /**
  -	* The <code>doFilter</code> method of the Filter is called by the container
  -	* each time a request/response pair is passed through the chain due
  -	* to a client request for a resource at the end of the chain. The FilterChain passed into
this
  -	* method allows the Filter to pass on the request and response to the next entity in the
  -	* chain.<p>
  -	* This method first examines the request to check whether the client support compression.
<br>
  -	* It simply just pass the request and response if there is no support for compression.<br>
  -	* If the compression support is available, it creates a CompressionServletResponseWrapper
object which
  -	* compresses the content and modifies the header if the content length is big enough.
  -	* It then invokes the next entity in the chain using the FilterChain object (<code>chain.doFilter()</code>),
<br>
  -	**/
  +        if (debug > 0) {
  +            System.out.println("@doFilter");
  +        }
   
  -  public void doFilter ( ServletRequest request, ServletResponse response, FilterChain
chain ) throws IOException, ServletException {
  +        boolean supportCompression = false;
  +        if (request instanceof HttpServletRequest) {
  +            Enumeration e =
  +                ((HttpServletRequest)request).getHeaders("Accept-Encoding");
  +            while (e.hasMoreElements()) {
  +                String name = (String)e.nextElement();
                if (name.indexOf("gzip")
!= -1) {
  +                    if (debug > 0) {
  +                        System.out.println("supports compression");
  +                    }
  +                    supportCompression = true;
  +                } else {
  +                    if (debug > 0) {
  +                        System.out.println("no suuport for compresion");
  +                    }
  +                }
  +            }
  +        }
   
  -    if (debug > 0) {
  -      System.out.println("@doFilter");
  -    }
  -    boolean supportCompression = false;
  -    if (request instanceof HttpServletRequest) {
  -      Enumeration e = ((HttpServletRequest)request).getHeaders("Accept-Encoding");
  -      while (e.hasMoreElements()) {
  -        String name = (String)e.nextElement();
  -        if (name.indexOf("gzip") != -1) {
  -          if (debug > 0) {
  -            System.out.println("supports compression");
  -          }
  -          supportCompression = true;
  +        if (!supportCompression) {
  +            if (debug > 0) {
  +                System.out.println("doFilter gets called wo compression");
  +            }
  +            chain.doFilter(request, response);
  +            return;
           } else {
  -          if (debug > 0) {
  -            System.out.println("no suuport for compresion");
  -          }
  -        }
  -      }
  -    }
  -    if (!supportCompression) {
  -      if (debug > 0) {
  -        System.out.println("doFilter gets called wo compression");
  -      }
  -      chain.doFilter(request, response);
  -      return;
  -    } else {
  -      if (response instanceof HttpServletResponse) {
  -        CompressionServletResponseWrapper wrappedResponse = new CompressionServletResponseWrapper((HttpServletResponse)response);
  -        wrappedResponse.setCompressionThreshold(compressionThreshold);
  -        if (debug > 0) {
  -          System.out.println("doFilter gets called with compression");
  +            if (response instanceof HttpServletResponse) {
  +                CompressionServletResponseWrapper wrappedResponse =
  +                    new CompressionServletResponseWrapper((HttpServletResponse)response);
  +                wrappedResponse.setCompressionThreshold(compressionThreshold);
  +                if (debug > 0) {
  +                    System.out.println("doFilter gets called with compression");
  +                }
  +                chain.doFilter(request, wrappedResponse);
  +                return;
  +            }
           }
  -        chain.doFilter(request, wrappedResponse);
  -        return;
  -      }
       }
  -  }
   }
   
  
  
  
  1.3       +19 -17    jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilterTestServlet.java
  
  Index: CompressionFilterTestServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilterTestServlet.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CompressionFilterTestServlet.java	2001/03/22 17:49:25	1.2
  +++ CompressionFilterTestServlet.java	2001/09/06 04:18:54	1.3
  @@ -1,8 +1,8 @@
   /*
    * CompressionFilterTestServlet.java
  - * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilterTestServlet.java,v
1.2 2001/03/22 17:49:25 amyroh Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/03/22 17:49:25 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilterTestServlet.java,v
1.3 2001/09/06 04:18:54 amyroh Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/09/06 04:18:54 $
    *
    * ====================================================================
    *
  @@ -73,30 +73,32 @@
   /**
    * Very Simple test servlet to test compression filter
    * @author Amy Roh
  - * @version $Revision: 1.2 $, $Date: 2001/03/22 17:49:25 $
  + * @version $Revision: 1.3 $, $Date: 2001/09/06 04:18:54 $
    */
   
   public class CompressionFilterTestServlet extends HttpServlet {
   
       public void doGet(HttpServletRequest request, HttpServletResponse response)
  -        throws ServletException, IOException
  -    {
  +        throws ServletException, IOException {
   
  -      ServletOutputStream out = response.getOutputStream();
  -      response.setContentType("text/plain");
  +        ServletOutputStream out = response.getOutputStream();
  +        response.setContentType("text/plain");
   
  -      Enumeration e = ((HttpServletRequest)request).getHeaders("Accept-Encoding");
  -      while (e.hasMoreElements()) {
  -        String name = (String)e.nextElement();
        out.println(name);
  -        if (name.indexOf("gzip") != -1) {
  -          out.println("gzip supported -- able to compress");
  +        Enumeration e = ((HttpServletRequest)request).getHeaders("Accept-Encoding");
  +        while (e.hasMoreElements()) {
  +            String name = (String)e.nextElement();
            out.println(name);
  +            if (name.indexOf("gzip") != -1) {
  +                out.println("gzip supported -- able to compress");
  +            }
  +            else {
  +                out.println("gzip not supported");
  +            }
           }
  -        else out.println("gzip not supported");
  -      }
   
   
  -      out.println("Compression Filter Test Servlet");
  -      out.close();
  +        out.println("Compression Filter Test Servlet");
  +        out.close();
       }
  +
   }
   
  
  
  
  1.3       +90 -119   jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionResponseStream.java
  
  Index: CompressionResponseStream.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionResponseStream.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CompressionResponseStream.java	2001/03/22 17:49:26	1.2
  +++ CompressionResponseStream.java	2001/09/06 04:18:54	1.3
  @@ -1,8 +1,8 @@
   /*
    * CompressionResponseStream.java
  - * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionResponseStream.java,v
1.2 2001/03/22 17:49:26 amyroh Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/03/22 17:49:26 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionResponseStream.java,v
1.3 2001/09/06 04:18:54 amyroh Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/09/06 04:18:54 $
    *
    * ====================================================================
    *
  @@ -76,7 +76,7 @@
    * the CompressionServletResponseWrapper implementation.
    *
    * @author Amy Roh
  - * @version $Revision: 1.2 $, $Date: 2001/03/22 17:49:26 $
  + * @version $Revision: 1.3 $, $Date: 2001/09/06 04:18:54 $
    */
   
   public class CompressionResponseStream
  @@ -93,12 +93,11 @@
        */
       public CompressionResponseStream(HttpServletResponse response) throws IOException{
   
  -	    super();
  -	    closed = false;
  -      commit = false;
  -	    count = 0;
  -      this.response = response;
  -	    this.output = response.getOutputStream();
  +        super();
  +        closed = false;
  +        count = 0;
  +        this.response = response;
  +        this.output = response.getOutputStream();
   
       }
   
  @@ -121,7 +120,7 @@
        * Is it big enough to compress?
        */
       protected boolean compressionThresholdReached = false; 
  -    
  +
       /**
        * The number of data bytes currently in the buffer.
        */
  @@ -137,14 +136,7 @@
        */
       protected boolean closed = false;
   
  -
       /**
  -     * Should we commit the response when we are flushed?
  -     */
  -    protected boolean commit = true;
  -
  -
  -    /**
        * The number of bytes which have already been written to this stream.
        */
       protected int count = 0;
  @@ -166,42 +158,17 @@
        */
       protected ServletOutputStream output = null;
   
  -    // ------------------------------------------------------------- Properties
  -
  -
  -    /**
  -     * [Package Private] Return the "commit response on flush" flag.
  -     */
  -    boolean getCommit() {
  -
  -        return (this.commit);
  -
  -    }
  -
   
  -    /**
  -     * [Package Private] Set the "commit response on flush" flag.
  -     *
  -     * @param commit The new commit flag
  -     */
  -    void setCommit(boolean commit) {
  -
  -        this.commit = commit;
  -
  -    }
  -
  -
       // --------------------------------------------------------- Public Methods
   
   
  -
       /**
        * Set the compressionThreshold number and create buffer for this size
        */
       protected void setBuffer(int threshold) {
  -      compressionThreshold = threshold;
  -      buffer = new byte[compressionThreshold];
  -      //System.out.println("buffer is set to "+compressionThreshold);
  +        compressionThreshold = threshold;
  +        buffer = new byte[compressionThreshold];
  +        //System.out.println("buffer is set to "+compressionThreshold);
       }
   
       /**
  @@ -209,13 +176,17 @@
        * any further output data to throw an IOException.
        */
       public void close() throws IOException {
  +
  +        if (closed)
  +	        throw new IOException("This output stream has already been closed");
  +
  +        flush();
   
  -      if (closed)
  -	      throw new IOException("This output stream has already been closed");
  -      if (gzipstream!=null) {
  -        gzipstream.close();
  -      }
  -      flush();
  +        if (gzipstream!=null) {
  +            gzipstream.close();
  +        }
  +
  +        output.close();
   	    closed = true;
   
       }
  @@ -227,31 +198,32 @@
        */
       public void flush() throws IOException {
   
  -      //System.out.println("flush() @ CompressionResponseStream");
  -	    if (closed)
  -        throw new IOException("Cannot flush a closed output stream");
  -
  -      if (commit) {
  -	      if (bufferCount > 0) {
  -          //System.out.println("writing to original stream");
  -	        output.write(buffer, 0, bufferCount);
  -	        bufferCount = 0;
  -	      }
  -      } else {
  -        //System.out.println("commit false");
  -      }
  +        //System.out.println("flush() @ CompressionResponseStream");
  +        if (closed) {
  +            throw new IOException("Cannot flush a closed output stream");
  +        }
  +
  +        if (bufferCount > 0) {
  +            //System.out.println("writing to original stream");
  +            output.write(buffer, 0, bufferCount);
  +            bufferCount = 0;
  +        }
  +
  +        if (gzipstream!=null) {
  +            gzipstream.flush();
  +        }
   
       }
   
       public void flushToGZip() throws IOException {
   
  -      //System.out.println("flushToGZip() @ CompressionResponseStream");
  +        //System.out.println("flushToGZip() @ CompressionResponseStream");
   
  -      if (bufferCount > 0) {
  -        //System.out.println("flushing out to GZipStream");
  -        gzipstream.write(buffer, 0, bufferCount);
  -        bufferCount = 0;
  -      }
  +        if (bufferCount > 0) {
  +            //System.out.println("flushing out to GZipStream");
  +            gzipstream.write(buffer, 0, bufferCount);
  +            bufferCount = 0;
  +        }
   
       }
   
  @@ -264,20 +236,20 @@
        */
       public void write(int b) throws IOException {
   
  -      //System.out.print("write "+b+" in CompressionResponseStream ");
  -      if (closed)
  -	      throw new IOException("Cannot write to a closed output stream");
  -
  -      if ((bufferCount >= buffer.length) || (count>=compressionThreshold)) {
  -        compressionThresholdReached = true;
  -      }
  -
  -      if (compressionThresholdReached) {
  -        writeToGZip(b);
  -      } else {
  -	      buffer[bufferCount++] = (byte) b;
  -	      count++;
  -	    }
  +        //System.out.print("write "+b+" in CompressionResponseStream ");
  +        if (closed)
  +            throw new IOException("Cannot write to a closed output stream");
  +
  +        if ((bufferCount >= buffer.length) || (count>=compressionThreshold)) {
  +            compressionThresholdReached = true;
  +        }
  +
  +        if (compressionThresholdReached) {
  +            writeToGZip(b);
  +        } else {
  +	        buffer[bufferCount++] = (byte) b;
  +	        count++;
  +        }
   
       }
   
  @@ -292,13 +264,13 @@
   
       public void writeToGZip(int b) throws IOException {
   
  -      //System.out.println("writeToGZip (int b) compressing");
  -      if (gzipstream == null) {
  -        gzipstream = new GZIPOutputStream(output);
  -        flushToGZip();
  -        response.addHeader("Content-Encoding", "gzip");
  -      }
  -      gzipstream.write(b);
  +        //System.out.println("writeToGZip (int b) compressing");
  +        if (gzipstream == null) {
  +            gzipstream = new GZIPOutputStream(output);
  +            flushToGZip();
  +            response.addHeader("Content-Encoding", "gzip");
  +        }
  +        gzipstream.write(b);
   
       }
   
  @@ -312,7 +284,7 @@
        */
       public void write(byte b[]) throws IOException {
   
  -    	write(b, 0, b.length);
  +        write(b, 0, b.length);
   
       }
   
  @@ -329,35 +301,35 @@
        */
       public void write(byte b[], int off, int len) throws IOException {
   
  -      //System.out.println("second write in CompressionResponseStream");
  -    	if (closed)
  -	      throw new IOException("Cannot write to a closed output stream");
  -
  -	    if (len == 0)
  -	      return;
  -	    if (len <= (buffer.length - bufferCount)) {
  -	      System.arraycopy(b, off, buffer, bufferCount, len);
  -	      bufferCount += len;
  -	      count += len;
  -	      return;
  +        //System.out.println("second write in CompressionResponseStream");
  +        if (closed)
  +            throw new IOException("Cannot write to a closed output stream");
  +
  +        if (len == 0)
  +            return;
  +        if (len <= (buffer.length - bufferCount)) {
  +            System.arraycopy(b, off, buffer, bufferCount, len);
  +            bufferCount += len;
  +            count += len;
  +            return;
   	    }
   
  -	    // buffer full, start writing to gzipstream
  +        // buffer full, start writing to gzipstream
   
  -      writeToGZip(b, off, len);
  -	    count += len;
  +        writeToGZip(b, off, len);
  +        count += len;
   
       }
   
       public void writeToGZip(byte b[], int off, int len) throws IOException {
   
  -      //System.out.println("writeToGZip 2 compressing");
  -      if (gzipstream == null) {
  -        gzipstream = new GZIPOutputStream(output);
  -        flushToGZip();
  -        response.addHeader("Content-Encoding", "gzip");
  -      }
  -      gzipstream.write(b, off, len);
  +        //System.out.println("writeToGZip 2 compressing");
  +        if (gzipstream == null) {
  +            gzipstream = new GZIPOutputStream(output);
  +            flushToGZip();
  +            response.addHeader("Content-Encoding", "gzip");
  +        }
  +        gzipstream.write(b, off, len);
   
       }
   
  @@ -368,9 +340,9 @@
       /**
        * Has this response stream been closed?
        */
  -    boolean closed() {
  +    public boolean closed() {
   
  -      return (this.closed);
  +        return (this.closed);
   
       }
   
  @@ -378,11 +350,10 @@
       /**
        * Reset the count of bytes written to this stream to zero.
        */
  -    void reset() {
  +    public void reset() {
   
  -    	count = 0;
  +        count = 0;
   
       }
  -
   
   }
  
  
  
  1.3       +38 -38    jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionServletResponseWrapper.java
  
  Index: CompressionServletResponseWrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionServletResponseWrapper.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CompressionServletResponseWrapper.java	2001/03/22 17:49:27	1.2
  +++ CompressionServletResponseWrapper.java	2001/09/06 04:18:54	1.3
  @@ -1,8 +1,8 @@
   /*
    * CompressionServletResponseWrapper.java
  - * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionServletResponseWrapper.java,v
1.2 2001/03/22 17:49:27 amyroh Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/03/22 17:49:27 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionServletResponseWrapper.java,v
1.3 2001/09/06 04:18:54 amyroh Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/09/06 04:18:54 $
    *
    * ====================================================================
    *
  @@ -83,23 +83,23 @@
    * the CompressionServletResponseStream implementation..
    *
    * @author Amy Roh
  - * @version $Revision: 1.2 $, $Date: 2001/03/22 17:49:27 $
  + * @version $Revision: 1.3 $, $Date: 2001/09/06 04:18:54 $
    */
   
   public class CompressionServletResponseWrapper extends HttpServletResponseWrapper {
   
       // ----------------------------------------------------- Constructor
   
  -  /**
  -   * Calls the parent constructor which creates a ServletResponse adaptor
  -   * wrapping the given response object.
  -   */
  -
  -  public CompressionServletResponseWrapper(HttpServletResponse response) {
  -    super(response);
  -    origResponse = response;
  -    //System.out.println("CompressionServletResponseWrapper constructor gets called");
  -  }
  +    /**
  +     * Calls the parent constructor which creates a ServletResponse adaptor
  +     * wrapping the given response object.
  +     */
  +
  +    public CompressionServletResponseWrapper(HttpServletResponse response) {
  +      super(response);
  +      origResponse = response;
  +      //System.out.println("CompressionServletResponseWrapper constructor gets called");
  +    }
   
   
       // ----------------------------------------------------- Instance Variables
  @@ -136,6 +136,7 @@
        */
       protected int threshold = 0;
   
  +
       // --------------------------------------------------------- Public Methods
   
   
  @@ -143,10 +144,10 @@
        * Set threshold number
        */
       public void setCompressionThreshold(int threshold) {
  -      //System.out.println("setCompressionThreshold @ CompressionServletResponseWrapper");
  -      this.threshold = threshold;
  +        //System.out.println("setCompressionThreshold @ CompressionServletResponseWrapper");
  +        this.threshold = threshold;
       }
  -    
  +
       /**
        * Create and return a ServletOutputStream to write the content
        * associated with this Response.
  @@ -155,8 +156,8 @@
        */
       public ServletOutputStream createOutputStream() throws IOException {
   
  -      //System.out.println("createOutputStream gets called");
  -    	return (new CompressionResponseStream(origResponse));
  +        //System.out.println("createOutputStream gets called");
  +        return (new CompressionResponseStream(origResponse));
   
       }
   
  @@ -172,8 +173,8 @@
        */
       public void flushBuffer() throws IOException {
   
  -      //  System.out.println("flush buffer @ CompressionServletResponseWrapper");
  -	    ((CompressionResponseStream)stream).flush();
  +        //  System.out.println("flush buffer @ CompressionServletResponseWrapper");
  +        ((CompressionResponseStream)stream).flush();
   
       }
   
  @@ -186,14 +187,13 @@
        */
       public ServletOutputStream getOutputStream() throws IOException {
   
  -    	if (writer != null)
  -	      throw new IllegalStateException("getWriter() has already been called for this response");
  +        if (writer != null)
  +            throw new IllegalStateException("getWriter() has already been called for this
response");
   
  -    	if (stream == null)
  -	      stream = createOutputStream();
  -      //System.out.println("stream is set to "+stream+" in getOutputStream");
  -      ((CompressionResponseStream) stream).setCommit(true);
  -      ((CompressionResponseStream) stream).setBuffer(threshold);
  +        if (stream == null)
  +            stream = createOutputStream();
  +        //System.out.println("stream is set to "+stream+" in getOutputStream");
  +        ((CompressionResponseStream) stream).setBuffer(threshold);
   	    return (stream);
   
       }
  @@ -207,18 +207,18 @@
        */
       public PrintWriter getWriter() throws IOException {
   
  -    	if (writer != null)
  -	      return (writer);
  +        if (writer != null)
  +            return (writer);
   
  -    	if (stream != null)
  -	      throw new IllegalStateException("getOutputStream() has already been called for this
response");
  +        if (stream != null)
  +            throw new IllegalStateException("getOutputStream() has already been called
for this response");
   
  -    	stream = createOutputStream();
  -      //System.out.println("strean is set to "+stream+" in getWriter");
  -      ((CompressionResponseStream) stream).setCommit(true);
  -      ((CompressionResponseStream) stream).setBuffer(threshold);
  -	    writer = new PrintWriter(stream);
  -	    return (writer);
  +        stream = createOutputStream();
  +        //System.out.println("strean is set to "+stream+" in getWriter");
  +        ((CompressionResponseStream) stream).setBuffer(threshold);
  +        writer = new PrintWriter(stream);
  +        return (writer);
   
       }
  +
   }
  
  
  

Mime
View raw message