remm        02/03/09 09:39:28

  Modified:    coyote/src/java/org/apache/coyote/tomcat4 OutputBuffer.java
  Log:
  - Fix WrappedForward05 test, caused by a fuzzy handling of the suspended
    flag.
  - Cleanup.
  
  Revision  Changes    Path
  1.5       +127 -17   
jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/OutputBuffer.java
  
  Index: OutputBuffer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/OutputBuffer.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- OutputBuffer.java 9 Mar 2002 00:15:40 -0000       1.4
  +++ OutputBuffer.java 9 Mar 2002 17:39:28 -0000       1.5
  @@ -88,7 +88,8 @@
       // -------------------------------------------------------------- Constants
   
   
  -    public static final String DEFAULT_ENCODING="ISO-8859-1";
  +    public static final String DEFAULT_ENCODING = 
  +        org.apache.coyote.Constants.DEFAULT_CHARACTER_ENCODING;
       public static final int DEFAULT_BUFFER_SIZE = 8*1024;
       static final int debug = 0;
   
  @@ -104,41 +105,96 @@
       // ----------------------------------------------------- Instance Variables
   
   
  -    private int defaultBufferSize = DEFAULT_BUFFER_SIZE;
  -    private int defaultCharBufferSize = DEFAULT_BUFFER_SIZE / 2 ;
  +    /**
  +     * The byte buffer.
  +     */
  +    private ByteChunk bb;
  +
  +
  +    /**
  +     * The chunk buffer.
  +     */
  +    private CharChunk cb;
  +
   
  +    /**
  +     * State of the output buffer.
  +     */
       private int state = 0;
   
  -    // statistics
  +
  +    /**
  +     * Number of bytes written.
  +     */
       private int bytesWritten = 0;
  -    private int charsWritten;
   
  +
  +    /**
  +     * Number of chars written.
  +     */
  +    private int charsWritten = 0;
  +
  +
  +    /**
  +     * Flag which indicates if the output buffer is closed.
  +     */
       private boolean closed = false;
  -    private boolean doFlush = false;
  +
   
       /**
  -     * The buffer
  +     * Do a flush on the next operation.
        */
  -    private ByteChunk bb;
  -    private CharChunk cb;
  +    private boolean doFlush = false;
  +
   
       /**
        * Byte chunk used to output bytes.
        */
       private ByteChunk outputChunk = new ByteChunk();
   
  +
  +    /**
  +     * Encoding to use.
  +     */
       private String enc;
  +
  +
  +    /**
  +     * Encoder is set.
  +     */
       private boolean gotEnc = false;
   
  +
  +    /**
  +     * List of encoders.
  +     */
       protected Hashtable encoders = new Hashtable();
  +
  +
  +    /**
  +     * Current char to byte converter.
  +     */
       protected C2BConverter conv;
   
  +
  +    /**
  +     * Associated Coyote response.
  +     */
       private Response coyoteResponse;
   
  +
  +    /**
  +     * Suspended flag. All output bytes will be swallowed if this is true.
  +     */
       private boolean suspended = false;
   
  +
  +    /**
  +     * True if the total response size can be computed.
  +     */
       private boolean knownResponseSize = false;
   
  +
       // ----------------------------------------------------------- Constructors
   
   
  @@ -152,6 +208,11 @@
       }
   
   
  +    /**
  +     * Alternate constructor which allows specifying the initial buffer size.
  +     * 
  +     * @param size Buffer size to use
  +     */
       public OutputBuffer(int size) {
   
           bb = new ByteChunk(size);
  @@ -169,6 +230,8 @@
   
       /**
        * Associated Coyote response.
  +     * 
  +     * @param coyoteResponse Associated Coyote response
        */
       public void setResponse(Response coyoteResponse) {
        this.coyoteResponse = coyoteResponse;
  @@ -177,6 +240,8 @@
   
       /**
        * Get associated Coyote response.
  +     * 
  +     * @return the associated Coyote response
        */
       public Response getResponse() {
           return this.coyoteResponse;
  @@ -185,6 +250,8 @@
   
       /**
        * Is the response output suspended ?
  +     * 
  +     * @return suspended flag value
        */
       public boolean isSuspended() {
           return this.suspended;
  @@ -193,6 +260,8 @@
   
       /**
        * Set the suspended flag.
  +     * 
  +     * @param suspended New suspended flag value
        */
       public void setSuspended(boolean suspended) {
           this.suspended = suspended;
  @@ -231,9 +300,18 @@
       }
   
   
  +    /**
  +     * Close the output buffer. This tries to calculate the response size if 
  +     * the response has not been committed yet.
  +     * 
  +     * @throws IOException An underlying IOException occurred
  +     */
       public void close()
           throws IOException {
   
  +        if (suspended)
  +            return;
  +
           if (!coyoteResponse.isCommitted()) {
               knownResponseSize = true;
           }
  @@ -244,9 +322,17 @@
       }
   
   
  +    /**
  +     * Flush bytes or chars contained in the buffer.
  +     * 
  +     * @throws IOException An underlying IOException occurred
  +     */
       public void flush()
           throws IOException {
   
  +        if (suspended)
  +            return;
  +
           doFlush = true;
           if (state == CHAR_STATE) {
               cb.flushBuffer();
  @@ -261,12 +347,18 @@
       }
   
   
  -    // ------------------------------------------------------------- Properties
  +    // ------------------------------------------------- Bytes Handling Methods
   
   
       /** 
        * Sends the buffer data to the client output, checking the
        * state of Response and calling the right interceptors.
  +     * 
  +     * @param buf Byte buffer to be written to the response
  +     * @param off Offset
  +     * @param cnt Length
  +     * 
  +     * @throws IOException An underlying IOException occurred
        */
       public void realWriteBytes(byte buf[], int off, int cnt)
        throws IOException {
  @@ -274,8 +366,6 @@
           if (debug > 2)
               log("realWrite(b, " + off + ", " + cnt + ") " + coyoteResponse);
   
  -        if (suspended)
  -            return;
           if (closed)
               return;
           if (coyoteResponse == null)
  @@ -294,12 +384,11 @@
       }
   
   
  -    // -------------------- Adding bytes to the buffer -------------------- 
  -    // Like BufferedOutputStream, without sync
  -
  -
       public void write(byte b[], int off, int len) throws IOException {
   
  +        if (suspended)
  +            return;
  +
           if (state == CHAR_STATE)
               cb.flushBuffer();
           state = BYTE_STATE;
  @@ -332,6 +421,9 @@
       public void writeByte(int b)
           throws IOException {
   
  +        if (suspended)
  +            return;
  +
           if (state == CHAR_STATE)
               cb.flushBuffer();
           state = BYTE_STATE;
  @@ -345,12 +437,15 @@
       }
   
   
  -    // -------------------- Adding chars to the buffer
  +    // ------------------------------------------------- Chars Handling Methods
   
   
       public void write(int c)
           throws IOException {
   
  +        if (suspended)
  +            return;
  +
           state = CHAR_STATE;
   
           if (debug > 0)
  @@ -365,6 +460,9 @@
       public void write(char c[])
           throws IOException {
   
  +        if (suspended)
  +            return;
  +
           write(c, 0, c.length);
   
       }
  @@ -373,6 +471,9 @@
       public void write(char c[], int off, int len)
           throws IOException {
   
  +        if (suspended)
  +            return;
  +
           state = CHAR_STATE;
   
           if (debug > 0)
  @@ -387,6 +488,9 @@
       public void write(StringBuffer sb)
           throws IOException {
   
  +        if (suspended)
  +            return;
  +
           state = CHAR_STATE;
   
           if (debug > 1)
  @@ -405,6 +509,9 @@
       public void write(String s, int off, int len)
           throws IOException {
   
  +        if (suspended)
  +            return;
  +
           state=CHAR_STATE;
   
           if (debug > 1)
  @@ -420,6 +527,9 @@
   
       public void write(String s)
           throws IOException {
  +
  +        if (suspended)
  +            return;
   
           state = CHAR_STATE;
           if (s==null)
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to