You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ol...@apache.org on 2004/10/10 17:16:44 UTC
cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/server SimpleHttpServerConnection.java
olegk 2004/10/10 08:16:44
Modified: httpclient/src/java/org/apache/commons/httpclient
ChunkedInputStream.java
httpclient/src/test/org/apache/commons/httpclient/server
SimpleHttpServerConnection.java
Removed: httpclient/src/test/org/apache/commons/httpclient
SimpleChunkedInputStream.java
Log:
ChunkedInputStream made more reusable by making HttpMethod parameter optional
Contributed by Oleg Kalnichevski
Reviewed by Michael Becke
Revision Changes Path
1.23 +36 -18 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ChunkedInputStream.java
Index: ChunkedInputStream.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ChunkedInputStream.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- ChunkedInputStream.java 18 Apr 2004 23:51:34 -0000 1.22
+++ ChunkedInputStream.java 10 Oct 2004 15:16:44 -0000 1.23
@@ -80,33 +80,47 @@
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 that associates the chunked input stream with a
+ * {@link HttpMethod HTTP method}. Usually it should be the same {@link HttpMethod
+ * HTTP method} the chunked input stream originates from. If chunked input stream
+ * contains any footers (trailing headers), they will be added to the associated
+ * {@link HttpMethod HTTP method}.
*
- *
- * @param in must be non-null
- * @param method must be non-null
+ * @param in the raw input stream
+ * @param method the HTTP method to associate this input stream with. Can be <tt>null</tt>.
+ * 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 +315,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]);
+ }
}
}
1.12 +5 -5 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/server/SimpleHttpServerConnection.java
Index: SimpleHttpServerConnection.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/server/SimpleHttpServerConnection.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- SimpleHttpServerConnection.java 6 Oct 2004 03:39:59 -0000 1.11
+++ SimpleHttpServerConnection.java 10 Oct 2004 15:16:44 -0000 1.12
@@ -38,13 +38,13 @@
import java.io.UnsupportedEncodingException;
import java.net.Socket;
+import org.apache.commons.httpclient.ChunkedInputStream;
import org.apache.commons.httpclient.ContentLengthInputStream;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HeaderGroup;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpParser;
import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.SimpleChunkedInputStream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -206,7 +206,7 @@
} else {
Header transferEncoding = headerGroup.getFirstHeader("Transfer-Encoding");
if (transferEncoding != null && transferEncoding.getValue().indexOf("chunked") != -1) {
- contentStream = new SimpleChunkedInputStream(is, DEFAULT_CONTENT_CHARSET);
+ contentStream = new ChunkedInputStream(is);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org