Folks,
I would like to make ChunkedInputStream a little more reusable by making
HttpMethod parameter optional. Please let me know if you agree/disagree

Oleg   


***************************************************************************************************
The information in this email is confidential and may be legally privileged.  Access 
to this email by anyone other than the intended addressee is unauthorized.  If you are 
not the intended recipient of this message, any review, disclosure, copying, 
distribution, retention, or any action taken or omitted to be taken in reliance on it 
is prohibited and may be unlawful.  If you are not the intended recipient, please 
reply to or forward a copy of this message to the sender and delete the message, any 
attachments, and any copies thereof from your system.
***************************************************************************************************
Index: ChunkedInputStream.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ChunkedInputStream.java,v
retrieving revision 1.22
diff -u -r1.22 ChunkedInputStream.java
--- ChunkedInputStream.java	18 Apr 2004 23:51:34 -0000	1.22
+++ ChunkedInputStream.java	8 Oct 2004 14:15:54 -0000
@@ -49,7 +49,7 @@
  * not requiring the client to remember to read the entire contents of the
  * response.</p>
  *
- * @author Ortwin Glï
+ * @author Ortwin Glueck
  * @author Sean C. Sullivan
  * @author Martin Elwin
  * @author Eric Johnson
@@ -80,33 +80,41 @@
     private boolean closed = false;
 
     /** The method that this stream came from */
-    private HttpMethod method;
+    private HttpMethod method = null;
 
     /** Log object for this class. */
     private static final Log LOG = LogFactory.getLog(ChunkedInputStream.class);
+
     /**
+     * ChunkedInputStream constructor
      *
-     *
-     * @param in must be non-null
-     * @param method must be non-null
+     * @param in the raw input stream
+     * @param method the originating HTTP method. Can be <tt>null</tt>.
      *
      * @throws IOException If an IO error occurs
      */
     public ChunkedInputStream(
         final InputStream in, final HttpMethod method) throws IOException {
             
-      if (in == null) {
-        throw new IllegalArgumentException("InputStream parameter may not be null");
-      }
-      if (method == null) {
-        throw new IllegalArgumentException("HttpMethod parameter may not be null");
-      }
+    	if (in == null) {
+    		throw new IllegalArgumentException("InputStream parameter may not be null");
+    	}
         this.in = in;
         this.method = method;
         this.pos = 0;
     }
 
     /**
+     * ChunkedInputStream constructor
+     *
+     * @param in the raw input stream
+     *
+     * @throws IOException If an IO error occurs
+     */
+    public ChunkedInputStream(final InputStream in) throws IOException {
+    	this(in, null);
+    }
+    /**
      * <p> Returns all the data in a chunked stream in coalesced form. A chunk
      * is followed by a CRLF. The method returns -1 as soon as a chunksize of 0
      * is detected.</p>
@@ -301,17 +309,21 @@
     private void parseTrailerHeaders() throws IOException {
         Header[] footers = null;
         try {
-            footers = HttpParser.parseHeaders(in, 
-                method.getParams().getHttpElementCharset());
+            String charset = "US-ASCII";
+            if (this.method != null) {
+                charset = this.method.getParams().getHttpElementCharset();
+            }
+            footers = HttpParser.parseHeaders(in, charset);
         } catch(HttpException e) {
             LOG.error("Error parsing trailer headers", e);
             IOException ioe = new IOException(e.getMessage());
             ExceptionUtil.initCause(ioe, e); 
             throw ioe;
         }
-        
-        for (int i = 0; i < footers.length; i++) {
-            method.addResponseFooter(footers[i]);
+        if (this.method != null) {
+            for (int i = 0; i < footers.length; i++) {
+                this.method.addResponseFooter(footers[i]);
+            }
         }
     }
 
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to