Jandalf

I have tried to incorporate your suggestions into the new patch. I left
ugly cast unchanged, though. I believe it's justified in this specific
case

Any other comments, suggestions, objections?

Cheers

Oleg

On Thu, 2003-02-27 at 14:37, Oleg Kalnichevski wrote:
> On Thu, 2003-02-27 at 06:24, Jeffrey Dever wrote:
> > Hey Odi,
> > A few comments:
> > 
> > - certainly would prefer Wire, WireLogInputStream, WireLogOutputStream 
> > to be package access, not public
> 
> So do I. I just find it illogical that HttpMethodBase and all classes
> derived from it reside in different packages. That causes the problem in
> the first place. Visibility of Wire, WireLogInputStream,
> WireLogOutputStream classes should have been restricted to
> org.apache.commons.httpclient.methods package in my opinion, which
> should have included HttpMethodBase.
> 
> 
> > - like the idea of the log stream working like tee to send the ouput to 
> > destination and to log
> > - Wire.wire has a cast to (char).  Could cause unicode problems?
> 
> I know it broke good programming practice here, which I had been
> preaching myself not that long ago. I found it justified, though, in
> this very specific case as I deem more important ability to escape CR &
> LF and other nasty characters in the wire log. I would personally rather
> prefer a hex dump of all characters outside 32-127 ASCII range   
> 
> 
> 
> > - can MultipartPost and EntityEnclosing drop reliance on log logic?   
> > conn.getRequestOutputStream() could return a WireLogOutputStream which 
> > would help with the first point above.
> > 
> 
> I believe this can be done. I regret having overlooked this possibility.
> Cheers
> 
> Oleg
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
Index: java/org/apache/commons/httpclient/ChunkedOutputStream.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ChunkedOutputStream.java,v
retrieving revision 1.8
diff -u -r1.8 ChunkedOutputStream.java
--- java/org/apache/commons/httpclient/ChunkedOutputStream.java	8 Feb 2003 19:22:49 -0000	1.8
+++ java/org/apache/commons/httpclient/ChunkedOutputStream.java	27 Feb 2003 14:48:13 -0000
@@ -103,9 +103,6 @@
     /** Log object for this class. */
     private static final Log LOG = LogFactory.getLog(ChunkedOutputStream.class);
 
-    /** Log for any wire messages. */
-    private static final Log WIRE_LOG = LogFactory.getLog("httpclient.wire");
-
     // ----------------------------------------------------- Instance Variables
 
     /** Has this stream been closed? */
@@ -190,10 +187,7 @@
         stream.write(CRLF, 0, CRLF.length);
         stream.write(b);
         stream.write(ENDCHUNK, 0, ENDCHUNK.length);
-        if (WIRE_LOG.isDebugEnabled()) {
-            WIRE_LOG.debug(">> byte 1 \\r\\n (chunk length \"header\")");
-            WIRE_LOG.debug(">> byte " + b + "\\r\\n (chunked byte)");
-        }
+        LOG.debug("Writing chunk (length: 1)");
     }
 
     /**
@@ -215,11 +209,8 @@
         stream.write(chunkHeader, 0, chunkHeader.length);
         stream.write(b, off, len);
         stream.write(ENDCHUNK, 0, ENDCHUNK.length);
-        if (WIRE_LOG.isDebugEnabled()) {
-            WIRE_LOG.debug(">> byte(s)" + len + " \\r\\n (chunk length "
-                + "\"header\")");
-            WIRE_LOG.debug(">> \"" + new String(b, off, len)
-                + "\"\\r\\n (chunked bytes)");
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Writing chunk (length: " + len + ")");
         }
     }
 
@@ -239,7 +230,7 @@
                 stream.write(ZERO, 0, ZERO.length);
                 stream.write(CRLF, 0, CRLF.length);
                 stream.write(ENDCHUNK, 0, ENDCHUNK.length);
-                WIRE_LOG.debug(">> byte 0 \\r\\n\\r\\n (final chunk)");
+                LOG.debug("Writing closing chunk");
             } catch (IOException e) {
                 LOG.debug("Unexpected exception caught when closing "
                     + "output stream", e);
Index: java/org/apache/commons/httpclient/HttpConnection.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java,v
retrieving revision 1.47
diff -u -r1.47 HttpConnection.java
--- java/org/apache/commons/httpclient/HttpConnection.java	27 Feb 2003 13:38:24 -0000	1.47
+++ java/org/apache/commons/httpclient/HttpConnection.java	27 Feb 2003 14:48:13 -0000
@@ -596,7 +596,11 @@
         throws IOException, IllegalStateException {
         LOG.trace("enter HttpConnection.getRequestOutputStream()");
         assertOpen();
-        return outputStream;
+        OutputStream out = this.outputStream;
+        if (Wire.enabled()) {
+            out = new WireLogOutputStream(out);
+        }
+        return out;
     }
 
     /**
@@ -745,10 +749,6 @@
 
         assertOpen();
 
-        if (WIRE_LOG.isDebugEnabled()) {
-            String dataString = new String(data, offset, length, "ISO-8859-1");
-            WIRE_LOG.debug(">> \"" + dataString + "\" [\\r\\n]");
-        }
         try {
             outputStream.write(data, offset, length);
         } catch (SocketException se) {
@@ -776,10 +776,7 @@
         LOG.trace("enter HttpConnection.writeLine(byte[])");
 
         assertOpen();
-        if (WIRE_LOG.isDebugEnabled() && (data.length > 0)) {
-            String dataString = HttpConstants.getContentString(data);
-            WIRE_LOG.debug(">> \"" + dataString.trim() + "\" [\\r\\n]");
-        }
+ 
         try {
             outputStream.write(data);
             writeLine();
@@ -804,7 +801,6 @@
         throws IOException, IllegalStateException, HttpRecoverableException {
         LOG.trace("enter HttpConnection.writeLine()");
 
-        WIRE_LOG.debug(">> [\\r\\n]");
         try {
             outputStream.write(CRLF);
         } catch (SocketException se) {
@@ -1060,9 +1056,6 @@
 
     /** Log object for this class. */
     private static final Log LOG = LogFactory.getLog(HttpConnection.class);
-    
-    /** Log for any wire messages. */
-    private static final Log WIRE_LOG = LogFactory.getLog("httpclient.wire");
     
     // ----------------------------------------------------- Instance Variables    
     /** My host. */
Index: java/org/apache/commons/httpclient/HttpMethodBase.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
retrieving revision 1.117
diff -u -r1.117 HttpMethodBase.java
--- java/org/apache/commons/httpclient/HttpMethodBase.java	25 Feb 2003 23:20:23 -0000	1.117
+++ java/org/apache/commons/httpclient/HttpMethodBase.java	27 Feb 2003 14:48:19 -0000
@@ -147,9 +147,6 @@
     /** Log object for this class. */
     private static final Log LOG = LogFactory.getLog(HttpMethod.class);
 
-    /** Log for any wire messages. */
-    private static final Log WIRE_LOG = LogFactory.getLog("httpclient.wire");
-
     /** The User-Agent header sent on every request. */
     protected static final Header USER_AGENT;
 
@@ -665,7 +662,7 @@
             try {
                 ByteArrayOutputStream os = new ByteArrayOutputStream();
                 InputStream is = getResponseBodyAsStream();
-                byte[] buffer = new byte[10000];
+                byte[] buffer = new byte[4096];
                 int len;
                 while ((len = is.read(buffer)) > 0) {
                     os.write(buffer, 0, len);
@@ -1803,7 +1800,7 @@
         Header lengthHeader = getResponseHeader("Content-Length");
         Header transferEncodingHeader = getResponseHeader("Transfer-Encoding");
         InputStream is = conn.getResponseInputStream();
-        if (WIRE_LOG.isDebugEnabled()) {
+        if (Wire.enabled()) {
             is = new WireLogInputStream(is);
         }
         InputStream result = null;
@@ -1889,6 +1886,11 @@
 
         getResponseHeaderGroup().clear();
         Header[] headers = HttpParser.parseHeaders(conn.getResponseInputStream());
+        if (Wire.enabled()) {
+            for (int i = 0; i < headers.length; i++) {
+                Wire.input(headers[i].toExternalForm());
+            }
+        }
         getResponseHeaderGroup().setHeaders(headers);
     }
 
@@ -1930,7 +1932,9 @@
                 + " line from the response: unable to find line starting with"
                 + " \"HTTP/\"");
         }
-
+        if (Wire.enabled()) {
+            Wire.input(statusString);
+        }
         //create the status line from the status string
         statusLine = new StatusLine(statusString);
 
@@ -1994,6 +1998,9 @@
         writeRequestLine(state, conn);
         writeRequestHeaders(state, conn);
         conn.writeLine(); // close head
+        if (Wire.enabled()) {
+            Wire.output("\r\n");
+        }
         bodySent = writeRequestBody(state, conn);
     }
 
@@ -2057,7 +2064,11 @@
 
         Header[] headers = getRequestHeaders();
         for (int i = 0; i < headers.length; i++) {
-            conn.print(headers[i].toExternalForm());
+            String s = headers[i].toExternalForm();
+            if (Wire.enabled()) {
+                Wire.output(s);
+            }
+            conn.print(s);
         }
     }
 
@@ -2081,6 +2092,9 @@
         LOG.trace(
             "enter HttpMethodBase.writeRequestLine(HttpState, HttpConnection)");
         String requestLine = getRequestLine(conn);
+        if (Wire.enabled()) {
+            Wire.output(requestLine);
+        }
         conn.print(requestLine);
     }
 
Index: java/org/apache/commons/httpclient/HttpParser.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpParser.java,v
retrieving revision 1.2
diff -u -r1.2 HttpParser.java
--- java/org/apache/commons/httpclient/HttpParser.java	20 Feb 2003 16:36:20 -0000	1.2
+++ java/org/apache/commons/httpclient/HttpParser.java	27 Feb 2003 14:48:14 -0000
@@ -21,8 +21,6 @@
     /** Log object for this class. */
     private static final Log LOG = LogFactory.getLog(HttpParser.class);
     
-    /** Log for any wire messages. */
-    private static final Log WIRE_LOG = LogFactory.getLog("httpclient.wire");
     /**
      * Constructor for HttpParser.
      */
@@ -57,9 +55,6 @@
                     break;
                 }
             }
-        }
-        if (WIRE_LOG.isDebugEnabled()) {
-            WIRE_LOG.debug("<< \"" + buf.toString() + (ch>0 ? "\" [\\r\\n]" : ""));
         }
         if (buf.size() == 0) {
             return null;
Index: java/org/apache/commons/httpclient/Wire.java
===================================================================
RCS file: java/org/apache/commons/httpclient/Wire.java
diff -N java/org/apache/commons/httpclient/Wire.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ java/org/apache/commons/httpclient/Wire.java	27 Feb 2003 14:48:14 -0000
@@ -0,0 +1,198 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    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
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    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", "Commons", and "Apache Software
+ *    Foundation" must not be used to endorse or promote products derived
+ *    from this software without prior written permission. For written
+ *    permission, please contact [EMAIL PROTECTED]
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ *    nor may "Apache" appear in their names without prior written
+ *    permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * [Additional notices, if required by prior licensing conditions]
+ *
+ */
+
+package org.apache.commons.httpclient;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ByteArrayInputStream;
+import java.io.Reader;
+import java.io.InputStreamReader;
+import java.io.BufferedReader;
+import java.io.UnsupportedEncodingException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Logs data to the wire LOG.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Oleg Kalnichevski</a>
+ * 
+ * @since 2.0beta1
+ */
+
+class Wire {
+
+    /** Log for any wire messages. */
+    private static final Log WIRE_LOG = LogFactory.getLog("httpclient.wire");
+
+    private static void wire(String header, InputStream instream)
+      throws IOException {
+        Reader reader = null;
+        try {
+            reader = new InputStreamReader(instream, "US-ASCII");
+        } catch (UnsupportedEncodingException e) {
+            reader = new InputStreamReader(instream);
+        }
+        StringBuffer buffer = new StringBuffer();
+        int ch;
+        while ((ch = reader.read()) != -1) {
+            if (ch == 13) {
+                buffer.append("[\\r]");
+            } else if (ch == 10){
+                    buffer.append("[\\n]\"");
+                    buffer.insert(0, "\"");
+                    buffer.insert(0, header);
+                    WIRE_LOG.debug(buffer.toString());
+                    buffer.setLength(0);
+            } else if ((ch < 32) || (ch > 127)) {
+                buffer.append("[0x");
+                buffer.append(Integer.toHexString(ch));
+                buffer.append("]");
+            } else {
+                buffer.append((char)ch);
+            }
+        } 
+        if (buffer.length() > 0) {
+            buffer.append("\"");
+            buffer.insert(0, "\"");
+            buffer.insert(0, header);
+            WIRE_LOG.debug(buffer.toString());
+        }
+    }
+
+
+    public static final boolean enabled() {
+        return WIRE_LOG.isDebugEnabled();
+    }    
+    
+    public static final void output(InputStream outstream)
+      throws IOException {
+        if (outstream == null) {
+            throw new IllegalArgumentException("Output may not be null"); 
+        }
+        wire(">> ", outstream);
+    }
+
+    public static final void input(InputStream instream)
+      throws IOException {
+        if (instream == null) {
+            throw new IllegalArgumentException("Input may not be null"); 
+        }
+        wire("<< ", instream);
+    }
+
+    public static final void output(byte[] b, int off, int len)
+      throws IOException {
+        if (b == null) {
+            throw new IllegalArgumentException("Output may not be null"); 
+        }
+        wire(">> ", new ByteArrayInputStream(b, off, len));
+    }
+
+    public static final void input(byte[] b, int off, int len)
+      throws IOException {
+        if (b == null) {
+            throw new IllegalArgumentException("Input may not be null"); 
+        }
+        wire("<< ", new ByteArrayInputStream(b, off, len));
+    }
+
+    public static final void output(byte[] b)
+      throws IOException {
+        if (b == null) {
+            throw new IllegalArgumentException("Output may not be null"); 
+        }
+        wire(">> ", new ByteArrayInputStream(b));
+    }
+
+    public static final void input(byte[] b)
+      throws IOException {
+        if (b == null) {
+            throw new IllegalArgumentException("Input may not be null"); 
+        }
+        wire("<< ", new ByteArrayInputStream(b));
+    }
+
+    public static final void output(int b)
+      throws IOException {
+        output(new byte[] {(byte)b});
+    }
+
+    public static final void input(int b)
+      throws IOException {
+        input(new byte[] {(byte)b});
+    }
+
+    public static final void output(final String s)
+      throws IOException {
+        if (s == null) {
+            throw new IllegalArgumentException("Output may noy be null"); 
+        }
+        output(s.getBytes());
+    }
+
+    public static final void input(final String s)
+      throws IOException {
+        if (s == null) {
+            throw new IllegalArgumentException("Input may noy be null"); 
+        }
+        input(s.getBytes());
+    }
+}
Index: java/org/apache/commons/httpclient/WireLogInputStream.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/WireLogInputStream.java,v
retrieving revision 1.8
diff -u -r1.8 WireLogInputStream.java
--- java/org/apache/commons/httpclient/WireLogInputStream.java	31 Jan 2003 00:33:36 -0000	1.8
+++ java/org/apache/commons/httpclient/WireLogInputStream.java	27 Feb 2003 14:48:20 -0000
@@ -74,29 +74,39 @@
  *
  * @author Ortwin GlО?╫
  * @author <a href="mailto:[EMAIL PROTECTED]">Mike Bowler</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Oleg Kalnichevski</a>
  * 
  * @since 2.0
  */
 
 class WireLogInputStream extends FilterInputStream {
+ 
     /** Log for any wire messages. */
     private static final Log WIRE_LOG = LogFactory.getLog("httpclient.wire");
 
+    /** Content encoding. */
+    private String charset = "US-ASCII";
+    
+    /** Original input stream. */
+    private InputStream in;    
+
     /**
      * Create an instance that wraps the specified input stream.
      * @param in The input stream.
      */
     public WireLogInputStream(InputStream in) {
         super(in);
+        this.in = in;
     }
-
     /**
      * 
      * @see java.io.InputStream#read(byte[], int, int)
      */
     public int read(byte[] b, int off, int len) throws IOException {
-        int l = super.read(b,  off,  len);
-        WIRE_LOG.debug("<< " + new String(b, off, len));
+        int l = this.in.read(b,  off,  len);
+        if (l > 0) {
+            Wire.input(b, off, l);
+        }
         return l;
     }
 
@@ -105,9 +115,9 @@
      * @see java.io.InputStream#read()
      */
     public int read() throws IOException {
-        int l = super.read();
+        int l = this.in.read();
         if (l > 0) { 
-            WIRE_LOG.debug("<< " + (char) l);
+            Wire.input(l);
         }
         return l;
     }
@@ -117,8 +127,10 @@
      * @see java.io.InputStream#read(byte[])
      */
     public int read(byte[] b) throws IOException {
-        int l = super.read(b);
-        WIRE_LOG.debug("<< " + HttpConstants.getString(b));
+        int l = this.in.read(b);
+        if (l > 0) {
+            Wire.input(b);
+        }
         return l;
     }
 }
Index: java/org/apache/commons/httpclient/WireLogOutputStream.java
===================================================================
RCS file: java/org/apache/commons/httpclient/WireLogOutputStream.java
diff -N java/org/apache/commons/httpclient/WireLogOutputStream.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ java/org/apache/commons/httpclient/WireLogOutputStream.java	27 Feb 2003 14:48:20 -0000
@@ -0,0 +1,125 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    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
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    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", "Commons", and "Apache Software
+ *    Foundation" must not be used to endorse or promote products derived
+ *    from this software without prior written permission. For written
+ *    permission, please contact [EMAIL PROTECTED]
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ *    nor may "Apache" appear in their names without prior written
+ *    permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * [Additional notices, if required by prior licensing conditions]
+ *
+ */
+
+package org.apache.commons.httpclient;
+
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.Reader;
+import java.io.InputStreamReader;
+import java.io.BufferedReader;
+import java.io.UnsupportedEncodingException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory; 
+
+/**
+ * Logs all data written to the wire LOG.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Oleg Kalnichevski</a>
+ * 
+ * @since 2.0beta1
+ */
+
+class WireLogOutputStream extends FilterOutputStream {
+
+    /** Log for any wire messages. */
+    private static final Log WIRE_LOG = LogFactory.getLog("httpclient.wire");
+
+    /** Original input stream. */
+    private OutputStream out;    
+
+    /**
+     * Create an instance that wraps the specified output stream.
+     * @param out The output stream.
+     */
+    public WireLogOutputStream(OutputStream out) {
+        super(out);
+        this.out = out;
+    }
+    
+    /**
+     * 
+     * @see java.io.OutputStream#write(byte[], int, int)
+     */
+    public void write(byte[] b, int off, int len) throws IOException {
+        this.out.write(b,  off,  len);
+        Wire.output(b, off, len);
+    }
+
+    /**
+     * 
+     * @see java.io.OutputStream#write()
+     */
+    public void write(int b) throws IOException {
+        this.out.write(b);
+        Wire.output(b);
+    }
+
+    /**
+     * 
+     * @see java.io.OutputStream#write(byte[])
+     */
+    public void write(byte[] b) throws IOException {
+        this.out.write(b);
+        Wire.output(b);
+    }
+}
Index: java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java,v
retrieving revision 1.10
diff -u -r1.10 EntityEnclosingMethod.java
--- java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java	25 Feb 2003 23:33:48 -0000	1.10
+++ java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java	27 Feb 2003 14:48:21 -0000
@@ -423,6 +423,7 @@
         this.repeatCount++;
 
         OutputStream outstream = conn.getRequestOutputStream();
+
         if (contentLength == CONTENT_LENGTH_CHUNKED) {
             outstream = new ChunkedOutputStream(outstream);
         }
Index: java/org/apache/commons/httpclient/methods/MultipartPostMethod.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/MultipartPostMethod.java,v
retrieving revision 1.11
diff -u -r1.11 MultipartPostMethod.java
--- java/org/apache/commons/httpclient/methods/MultipartPostMethod.java	25 Feb 2003 23:33:48 -0000	1.11
+++ java/org/apache/commons/httpclient/methods/MultipartPostMethod.java	27 Feb 2003 14:48:22 -0000
@@ -286,8 +286,9 @@
                 return false;
             }
         }
-        OutputStream out = conn.getRequestOutputStream();
-        Part.sendParts(out, getParts());
+        OutputStream outstream = conn.getRequestOutputStream();
+
+        Part.sendParts(outstream, getParts());
         return true;
     }
 

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

Reply via email to