You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bi...@apache.org on 2001/10/02 07:38:22 UTC

cvs commit: jakarta-tomcat/src/facade22/org/apache/tomcat/facade ServletInputStreamFacade.java

billbarker    01/10/01 22:38:22

  Modified:    src/facade22/org/apache/tomcat/facade
                        ServletInputStreamFacade.java
  Log:
  Implement the close method so that the class can be recycled.
  This fixes bug #3905
  
  Revision  Changes    Path
  1.6       +14 -0     jakarta-tomcat/src/facade22/org/apache/tomcat/facade/ServletInputStreamFacade.java
  
  Index: ServletInputStreamFacade.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/ServletInputStreamFacade.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ServletInputStreamFacade.java	2001/08/24 04:38:50	1.5
  +++ ServletInputStreamFacade.java	2001/10/02 05:38:21	1.6
  @@ -77,6 +77,7 @@
       private int bytesRead = 0;
       // Stop after reading ContentLength bytes. 
       private int limit = -1;
  +    private boolean closed=false;
   
       private Request reqA;
       
  @@ -98,12 +99,15 @@
   
       void recycle() {
   	limit=-1;
  +	closed=false;
       }
   
       // -------------------- ServletInputStream methods 
   
       public int read() throws IOException {
   	if( dL>0) debug("read() " + limit + " " + bytesRead );
  +	if(closed)
  +	    throw new IOException("Stream closed");
   	if (limit == -1) {
   	    // Ask the adapter for more data. We are in the 'no content-length'
   	    // case - i.e. chunked encoding ( acording to http spec CL is required
  @@ -137,6 +141,8 @@
   
       public int read(byte[] b, int off, int len) throws IOException {
   	if( dL>0) debug("read(" +  len + ") " + limit + " " + bytesRead );
  +	if(closed)
  +	    throw new IOException("Stream closed");
   	if (limit == -1) {
   	    int numRead = reqA.doRead(b, off, len);
   	    if (numRead > 0) {
  @@ -166,6 +172,14 @@
   
       public int readLine(byte[] b, int off, int len) throws IOException {
   	return super.readLine(b, off, len);
  +    }
  +
  +    /** Close the stream
  +     *  Since we re-cycle, we can't allow the call to super.close()
  +     *  which would permantely disable us.
  +     */
  +    public void close() {
  +	closed=true;
       }
   
       private static int dL=0;