You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by je...@apache.org on 2001/03/01 23:01:02 UTC

cvs commit: jakarta-slide/src/webdav/client/src/org/apache/webdav/lib ResponseInputStream.java RequestOutputStream.java

jericho     01/03/01 14:01:02

  Modified:    src/webdav/client/src/org/apache/webdav/lib
                        ResponseInputStream.java RequestOutputStream.java
  Log:
  - Some layout changes for indenting.
  
  Revision  Changes    Path
  1.3       +99 -100   jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/ResponseInputStream.java
  
  Index: ResponseInputStream.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/ResponseInputStream.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ResponseInputStream.java	2000/12/06 06:35:14	1.2
  +++ ResponseInputStream.java	2001/03/01 22:00:59	1.3
  @@ -1,13 +1,13 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/ResponseInputStream.java,v 1.2 2000/12/06 06:35:14 remm Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/12/06 06:35:14 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/ResponseInputStream.java,v 1.3 2001/03/01 22:00:59 jericho Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/03/01 22:00:59 $
    *
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -15,7 +15,7 @@
    * are met:
    *
    * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer. 
  + *    notice, this list of conditions and the following disclaimer.
    *
    * 2. Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in
  @@ -23,15 +23,15 @@
    *    distribution.
    *
    * 3. The end-user documentation included with the redistribution, if
  - *    any, must include the following acknowlegement:  
  - *       "This product includes software developed by the 
  + *    any, must include the following acknowlegement:
  + *       "This product includes software developed by the
    *        Apache Software Foundation (http://www.apache.org/)."
    *    Alternately, this acknowlegement may appear in the software itself,
    *    if and wherever such third-party acknowlegements normally appear.
    *
    * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
    *    Foundation" must not be used to endorse or promote products derived
  - *    from this software without prior written permission. For written 
  + *    from this software without prior written permission. For written
    *    permission, please contact apache@apache.org.
    *
    * 5. Products derived from this software may not be called "Apache"
  @@ -59,7 +59,7 @@
    *
    * [Additional notices, if required by prior licensing conditions]
    *
  - */ 
  + */
   
   
   package org.apache.webdav.lib;
  @@ -72,9 +72,9 @@
   
   /**
    * Socket input stream wrapper.
  - * 
  + *
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  - * @version $Revision: 1.2 $ $Date: 2000/12/06 06:35:14 $
  + * @version $Revision: 1.3 $ $Date: 2001/03/01 22:00:59 $
    */
   
   public class ResponseInputStream
  @@ -90,20 +90,20 @@
        * @param request The associated request
        */
       public ResponseInputStream(InputStream stream, Hashtable responseHeaders) {
  -        
  -	super();
  -	closed = false;
  -	count = 0;
  -        
  +
  +        super();
  +        closed = false;
  +        count = 0;
  +
           // Retrieving transfer encoding header
  -        Header transferEncoding = 
  +        Header transferEncoding =
               (Header) responseHeaders.get("transfer-encoding");
  -        if ((transferEncoding != null) 
  +        if ((transferEncoding != null)
               && (transferEncoding.getValue().indexOf("chunked") != -1))
               chunk = true;
  -        
  +
           // Retrieving content length header
  -        Header contentLength = 
  +        Header contentLength =
               (Header) responseHeaders.get("content-length");
           if (contentLength != null) {
               try {
  @@ -111,70 +111,70 @@
               } catch (NumberFormatException e) {
               }
           }
  -	
  +
           this.stream = stream;
   
       }
   
   
       // ----------------------------------------------------- Instance Variables
  -    
  -    
  +
  +
       /**
        * Has this stream been closed?
        */
       protected boolean closed = false;
  -    
  -    
  +
  +
       /**
        * Use chunking ?
        */
       protected boolean chunk = false;
  -    
  -    
  +
  +
       /**
        * True if the final chunk was found.
        */
       protected boolean endChunk = false;
  -    
  -    
  +
  +
       /**
        * Chunk buffer.
        */
       protected byte[] chunkBuffer = null;
  -    
  -    
  +
  +
       /**
        * Chunk length.
        */
       protected int chunkLength = 0;
  -    
  -    
  +
  +
       /**
        * Chunk buffer position.
        */
       protected int chunkPos = 0;
  -    
  -    
  +
  +
       /**
        * The number of bytes which have already been returned by this stream.
        */
       protected int count = 0;
  -    
  -    
  +
  +
       /**
        * The content length past which we will not read, or -1 if there is
        * no defined content length.
        */
       protected int length = -1;
  -    
  -    
  +
  +
       /**
        * The underlying input stream from which we should read data.
        */
       protected InputStream stream = null;
  -    
  -    
  +
  +
       // --------------------------------------------------------- Public Methods
   
   
  @@ -186,23 +186,23 @@
        */
       public void close()
           throws IOException {
  -/*        
  +/*
           // Xerces appears to doubly-close the input stream...
           if (closed)
               throw new IOException("Stream is already closed");
   */
  -        if (!closed) {        
  +        if (!closed) {
   
               if (chunk) {
  -            
  +
                   while (!endChunk) {
                       int b = read();
                       if (b < 0)
                           break;
                   }
  -            
  +
               } else {
  -            
  +
                   if (length > 0) {
                       while (count < length) {
                           int b = read();
  @@ -214,8 +214,8 @@
               closed = true;
           }
       }
  -    
  -    
  +
  +
       /**
        * Read and return a single byte from this input stream, or -1 if end of
        * file has been encountered.
  @@ -224,21 +224,21 @@
        */
       public int read()
           throws IOException {
  -        
  +
           // Has this stream been closed?
           if (closed)
               throw new IOException("Stream is closed");
  -        
  +
           if (endChunk)
               return (-1);
  -        
  +
           if (chunk) {
  -            
  +
               if ((chunkBuffer == null)
                   || (chunkPos == chunkLength)) {
  -                
  +
                   chunkPos = 0;
  -                
  +
                   try {
                       chunkLength = Integer.parseInt(readLine().trim(), 16);
                   } catch (NumberFormatException e) {
  @@ -248,97 +248,96 @@
                       close();
                       return -1;
                   }
  -                
  +
                   if (chunkLength == 0) {
  -                    
  +
                       // TODO : Parse the trailing headers, if any
                       readLine();
                       endChunk = true;
                       return (-1);
                       // TODO : Should the stream be automatically closed ?
  -                    
  +
                   } else {
  -                    
  +
                       if ((chunkBuffer == null)
                           || (chunkLength > chunkBuffer.length))
                           chunkBuffer = new byte[chunkLength];
  -                    
  +
                       // Now read the whole chunk into the buffer
  -                    
  +
                       int nbRead = 0;
                       int currentRead = 0;
  -                    
  +
                       while (nbRead < chunkLength) {
  -                        currentRead = 
  -                            stream.read(chunkBuffer, nbRead, 
  +                        currentRead =
  +                            stream.read(chunkBuffer, nbRead,
                                           chunkLength - nbRead);
                           if (currentRead == -1)
                               throw new IOException("Unexpected end of stream");
                           nbRead += currentRead;
                       }
  -                    
  +
                       // Skipping the CRLF
                       stream.read();
                       stream.read();
  -                                       
  +
                   }
  -                
  +
               }
  -            
  +
               return (chunkBuffer[chunkPos++]);
  -            
  +
           } else {
  -            
  +
               // Have we read the specified content length already?
               if ((length >= 0) && (count >= length))
  -                return (-1);	// End of file indicator
  -            
  +                return (-1);    // End of file indicator
  +
               // Read and count the next byte, then return it
               int b = stream.read();
               if (b >= 0)
                   count++;
               return (b);
  -            
  +
           }
  -        
  +
       }
   
   
       // -------------------------------------------------------- Private Methods
  -    
  +
   
       /**
  -     * Reads the input stream, one line at a time. Reads bytes into an array, 
  +     * Reads the input stream, one line at a time. Reads bytes into an array,
        * until it reads a certain number of bytes or reaches a newline character,
        * which it reads into the array as well.
  -     * 
  +     *
        * @param input Input stream on which the bytes are read
        * @return The line that was read, or <code>null</code> if end-of-file
        *  was encountered
  -     * @exception IOException	if an input or output exception has occurred
  +     * @exception IOException   if an input or output exception has occurred
        */
  -    private String readLine() 
  +    private String readLine()
           throws IOException {
  -        
  -	StringBuffer sb = new StringBuffer();
  -	while (true) {
  -	    int ch = stream.read();
  -	    if (ch < 0) {
  -		if (sb.length() == 0) {
  -		    return (null);
  -		} else {
  -		    break;
  -		}
  -	    } else if (ch == '\r') {
  -		continue;
  -	    } else if (ch == '\n') {
  -		break;
  -	    }
  -	    sb.append((char) ch);
  -	}
  -	return (sb.toString());
  -        
  -    }
  -    
  -    
  +
  +        StringBuffer sb = new StringBuffer();
  +        while (true) {
  +            int ch = stream.read();
  +            if (ch < 0) {
  +            if (sb.length() == 0) {
  +                return (null);
  +            } else {
  +                break;
  +            }
  +            } else if (ch == '\r') {
  +            continue;
  +            } else if (ch == '\n') {
  +            break;
  +            }
  +            sb.append((char) ch);
  +        }
  +        return (sb.toString());
  +
  +        }
  +
   }
  
  
  
  1.3       +47 -47    jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/RequestOutputStream.java
  
  Index: RequestOutputStream.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/RequestOutputStream.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RequestOutputStream.java	2001/01/22 04:49:26	1.2
  +++ RequestOutputStream.java	2001/03/01 22:01:00	1.3
  @@ -1,13 +1,13 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/RequestOutputStream.java,v 1.2 2001/01/22 04:49:26 remm Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/01/22 04:49:26 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/RequestOutputStream.java,v 1.3 2001/03/01 22:01:00 jericho Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/03/01 22:01:00 $
    *
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -15,7 +15,7 @@
    * are met:
    *
    * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer. 
  + *    notice, this list of conditions and the following disclaimer.
    *
    * 2. Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in
  @@ -23,15 +23,15 @@
    *    distribution.
    *
    * 3. The end-user documentation included with the redistribution, if
  - *    any, must include the following acknowlegement:  
  - *       "This product includes software developed by the 
  + *    any, must include the following acknowlegement:
  + *       "This product includes software developed by the
    *        Apache Software Foundation (http://www.apache.org/)."
    *    Alternately, this acknowlegement may appear in the software itself,
    *    if and wherever such third-party acknowlegements normally appear.
    *
    * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
    *    Foundation" must not be used to endorse or promote products derived
  - *    from this software without prior written permission. For written 
  + *    from this software without prior written permission. For written
    *    permission, please contact apache@apache.org.
    *
    * 5. Products derived from this software may not be called "Apache"
  @@ -59,7 +59,7 @@
    *
    * [Additional notices, if required by prior licensing conditions]
    *
  - */ 
  + */
   
   
   package org.apache.webdav.lib;
  @@ -72,9 +72,9 @@
   
   /**
    * Socket output stream wrapper.
  - * 
  + *
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  - * @version $Revision: 1.2 $ $Date: 2001/01/22 04:49:26 $
  + * @version $Revision: 1.3 $ $Date: 2001/03/01 22:01:00 $
    */
   
   public class RequestOutputStream
  @@ -90,29 +90,29 @@
        * @param stream Wrapped input stream
        */
       public RequestOutputStream(OutputStream stream) {
  -        
  -	super();
  -        
  +
  +        super();
  +
           this.stream = stream;
  -        
  +
       }
   
   
       // ----------------------------------------------------- Instance Variables
  -    
  -    
  +
  +
       /**
        * Has this stream been closed?
        */
       protected boolean closed = false;
  -    
  -    
  +
  +
       /**
        * The underlying input stream from which we should read data.
        */
       protected OutputStream stream = null;
  -    
  -    
  +
  +
       /**
        * True if chunking is allowed.
        */
  @@ -150,42 +150,42 @@
   
   
       // ------------------------------------------------------------- Properties
  -    
  -    
  +
  +
       /**
        * Use chunking flag setter.
        */
       public void setUseChunking(boolean useChunking) {
           this.useChunking = useChunking;
       }
  -    
  -    
  +
  +
       /**
        * Use chunking flag getter.
        */
       public boolean isUseChunking() {
           return useChunking;
       }
  -    
  -    
  +
  +
       // --------------------------------------------------------- Public Methods
  -    
  -    
  +
  +
       /**
  -     * Writes a <code>String</code> to the client, 
  -     * without a carriage return-line feed (CRLF) 
  +     * Writes a <code>String</code> to the client,
  +     * without a carriage return-line feed (CRLF)
        * character at the end.
        *
  -     * @param s			the <code>String</code to send to the client
  -     * @exception IOException 	if an input or output exception occurred
  +     * @param s         the <code>String</code to send to the client
  +     * @exception IOException   if an input or output exception occurred
        */
       public void print(String s) throws IOException {
  -	if (s == null)
  -            s = "null";
  -	int len = s.length();
  -	for (int i = 0; i < len; i++) {
  -	    write(s.charAt(i));
  -	}
  +        if (s == null)
  +                s = "null";
  +        int len = s.length();
  +        for (int i = 0; i < len; i++) {
  +            write(s.charAt(i));
  +        }
       }
   
   
  @@ -193,24 +193,24 @@
        * Writes a carriage return-line feed (CRLF)
        * to the client.
        *
  -     * @exception IOException 	if an input or output exception occurred
  +     * @exception IOException   if an input or output exception occurred
        */
       public void println() throws IOException {
  -	print("\r\n");
  +        print("\r\n");
       }
   
   
   
       /**
  -     * Writes a <code>String</code> to the client, 
  +     * Writes a <code>String</code> to the client,
        * followed by a carriage return-line feed (CRLF).
        *
  -     * @param s			the </code>String</code> to write to the client
  -     * @exception IOException 	if an input or output exception occurred
  +     * @param s         the </code>String</code> to write to the client
  +     * @exception IOException   if an input or output exception occurred
        */
       public void println(String s) throws IOException {
  -	print(s);
  -	println();
  +        print(s);
  +        println();
       }
   
   
  @@ -243,7 +243,7 @@
       public void write(byte[] b, int off, int len)
           throws IOException {
           if (useChunking) {
  -            byte chunkHeader[] = 
  +            byte chunkHeader[] =
                   (Integer.toHexString(len) + "\r\n").getBytes();
               stream.write(chunkHeader, 0, chunkHeader.length);
               stream.write(b, off, len);