commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/java/org/apache/commons/httpclient RequestOutputStream.java
Date Mon, 05 Aug 2002 13:14:23 GMT
dion        2002/08/05 06:14:23

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        RequestOutputStream.java
  Log:
  Remove tabs, fix docs
  
  Revision  Changes    Path
  1.13      +62 -78    jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/RequestOutputStream.java
  
  Index: RequestOutputStream.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/RequestOutputStream.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- RequestOutputStream.java	30 Jul 2002 03:01:47 -0000	1.12
  +++ RequestOutputStream.java	5 Aug 2002 13:14:22 -0000	1.13
  @@ -115,66 +115,44 @@
       // ------------------------------------------------------- Static Variables
   
       /** Log object for this class. */
  -    static private final Log log = LogFactory.getLog(RequestOutputStream.class);
  +    private static final Log log = LogFactory.getLog(RequestOutputStream.class);
   
       /** Log for any wire messages. */
  -    static private final Log wireLog = LogFactory.getLog("httpclient.wire");
  +    private static final Log wireLog = LogFactory.getLog("httpclient.wire");
   
       // ----------------------------------------------------- Instance Variables
   
  -    /**
  -     * Has this stream been closed?
  -     */
  +    /** Has this stream been closed? */
       private boolean closed = false;
   
  -
  -    /**
  -     * The underlying output stream to which we will write data.
  -     */
  +    /** The underlying output stream to which we will write data */
       private OutputStream stream = null;
   
  -
  -    /**
  -     * True if chunking is allowed.
  -     */
  +    /** True if chunking is allowed */
       private boolean useChunking = false;
   
  -
  -    /**
  -     * True if printing a chunk.
  -     */
  +    /** True if printing a chunk */
       private boolean writingChunk = false;
   
  +    /** End chunk */
  +    private static final byte ENDCHUNK[] = new byte[] {(byte) 13, (byte) 10};
   
  -    /**
  -     * End chunk.
  -     */
  -    private static final byte endChunk[] = new byte[] {(byte)13, (byte)10};
  -
  -
  -    /**
  -     * CRLF.
  -     */
  -    private static final byte crlf[] = new byte[] {(byte)13, (byte)10};
  -
  -
  -    /**
  -     * 0.
  -     */
  -    private static final byte zero[] = new byte[] {(byte)'0'};
  -
  +    /** CRLF */
  +    private static final byte CRLF[] = new byte[] {(byte) 13, (byte) 10};
   
  -    /**
  -     * 1.
  -     */
  -    private static final byte one[] = new byte[] {(byte)'1'};
  +    /** 0 */
  +    private static final byte ZERO[] = new byte[] {(byte) '0'};
   
  +    /** 1 */
  +    private static final byte ONE[] = new byte[] {(byte) '1'};
   
       // ------------------------------------------------------------- Properties
   
   
       /**
        * Use chunking flag setter.
  +     *
  +     * @param useChunking true if chunking is to be used, false otherwise
        */
       public void setUseChunking(boolean useChunking) {
           this.useChunking = useChunking;
  @@ -183,6 +161,8 @@
   
       /**
        * Use chunking flag getter.
  +     *
  +     * @return true if chunking is to be used, false otherwise
        */
       public boolean isUseChunking() {
           return useChunking;
  @@ -191,12 +171,11 @@
       // --------------------------------------------------------- Public Methods
   
       /**
  -     * Writes a <code>String</code> to the client,
  -     * without a carriage return-line feed (CRLF)
  -     * character at the end.
  +     * 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. Must
be non-null.
  -     * @exception IOException   if an input or output exception occurred
  +     * @param s the <code>String</code> to send to the client. Must be non-null.
  +     * @throws IOException if an input or output exception occurred
        */
       public void print(String s) throws IOException {
           log.trace("enter RequestOutputStream.print(String)");
  @@ -211,10 +190,9 @@
       }
   
       /**
  -     * Writes a carriage return-line feed (CRLF)
  -     * to the client.
  +     * Writes a carriage return-line feed (CRLF) to the client.
        *
  -     * @exception IOException   if an input or output exception occurred
  +     * @throws IOException   if an input or output exception occurred
        */
       public void println() throws IOException {
           print("\r\n");
  @@ -238,24 +216,23 @@
        * Write the specified byte to our output stream.
        *
        * @param b The byte to be written
  -     *
  -     * @exception IOException if an input/output error occurs
  +     * @throws IOException if an input/output error occurs
        */
       public void write(int b) throws IOException {
   
  -        //FIXME: If using chunking, the chunks are one byte long!
  +        //FIXME: If using chunking, the chunks are ONE byte long!
           if (useChunking) {
  -            stream.write(one, 0, one.length);
  -            stream.write(crlf, 0, crlf.length);
  +            stream.write(ONE, 0, ONE.length);
  +            stream.write(CRLF, 0, CRLF.length);
               stream.write(b);
  -            stream.write(endChunk, 0, endChunk.length);
  -            if(wireLog.isDebugEnabled()) {
  +            stream.write(ENDCHUNK, 0, ENDCHUNK.length);
  +            if (wireLog.isDebugEnabled()) {
                   wireLog.debug(">> byte 1 \\r\\n (chunk length \"header\")");
                   wireLog.debug(">> byte " + b + "\\r\\n (chunked byte)");
               }
           } else {
               stream.write(b);
  -            if(wireLog.isDebugEnabled()) {
  +            if (wireLog.isDebugEnabled()) {
                   wireLog.debug(">> byte " + b);
               }
           }
  @@ -263,24 +240,30 @@
   
       /**
        * Write the specified byte array.
  +     *
  +     * @param b the byte array to write out
  +     * @param off the offset within <code>b</code> to start writing from
  +     * @param len the length of data within <code>b</code> to write
  +     * @throws IOException when errors occur writing output
        */
       public void write(byte[] b, int off, int len) throws IOException {
           log.trace("enter RequestOutputStream.write(byte[], int, int)");
   
           if (useChunking) {
  -            byte chunkHeader[] =
  -                (Integer.toHexString(len) + "\r\n").getBytes();
  +            byte chunkHeader[] = (Integer.toHexString(len) + "\r\n").getBytes();
               stream.write(chunkHeader, 0, chunkHeader.length);
               stream.write(b, off, len);
  -            stream.write(endChunk, 0, endChunk.length);
  -            if(wireLog.isDebugEnabled()) {
  -                wireLog.debug(">> byte(s)" + len + " \\r\\n (chunk length \"header\")");
  -                wireLog.debug(">> \"" + new String(b,off,len)+ "\"\\r\\n (chunked
bytes)");
  +            stream.write(ENDCHUNK, 0, ENDCHUNK.length);
  +            if (wireLog.isDebugEnabled()) {
  +                wireLog.debug(">> byte(s)" + len + " \\r\\n (chunk length "
  +                    + "\"header\")");
  +                wireLog.debug(">> \"" + new String(b, off, len) 
  +                    + "\"\\r\\n (chunked bytes)");
               }
           } else {
               stream.write(b, off, len);
  -            if(wireLog.isDebugEnabled() && len > 0) {
  -                wireLog.debug(">> \"" + new String(b,off,len) + "\"");
  +            if (wireLog.isDebugEnabled() && len > 0) {
  +                wireLog.debug(">> \"" + new String(b, off, len) + "\"");
               }
           }
       }
  @@ -288,24 +271,25 @@
       /**
        * 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 stream
        */
       public void close() throws IOException {
           log.trace("enter RequestOutputStream.close()");
   
  -        if (this.closed == false) {
  +        if (!closed) {
               try {
  -	       if (useChunking) {
  -		  // Write the final chunk.
  -		  stream.write(zero, 0, zero.length);
  -		  stream.write(crlf, 0, crlf.length);
  -		  stream.write(endChunk, 0, endChunk.length);
  -		  if(wireLog.isDebugEnabled()) {
  -		     wireLog.debug(">> byte 0 \\r\\n\\r\\n (final chunk)");
  -		  }
  -	       }
  -	       super.close();
  +                if (useChunking) {
  +                    // Write the final chunk.
  +                    stream.write(ZERO, 0, ZERO.length);
  +                    stream.write(CRLF, 0, CRLF.length);
  +                    stream.write(ENDCHUNK, 0, ENDCHUNK.length);
  +                    wireLog.debug(">> byte 0 \\r\\n\\r\\n (final chunk)");
  +                }
  +                super.close();
               } catch (IOException ioe) {
  -	        log.debug("Unexpected exception caught when closing output stream", ioe);
  +                log.debug("Unexpected exception caught when closing output "
  +                    + " stream", ioe);
                   throw ioe;
               } finally {
                   this.closed = true;
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message