Author: olegk
Date: Wed Oct 19 13:11:38 2005
New Revision: 326673
URL: http://svn.apache.org/viewcvs?rev=326673&view=rev
Log:
EntityConsumer changed to static only and renamed to EntityUtils
Added:
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/EntityUtils.java
- copied, changed from r325854, jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/EntityConsumer.java
Removed:
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/EntityConsumer.java
Modified:
jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java
jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpEchoServer.java
jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpGet.java
jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpPost.java
jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/HttpRequestExecutorDemo.java
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpEntity.java
jakarta/httpclient/trunk/http-common/src/test/org/apache/http/entity/TestHttpEntities.java
Modified: jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java?rev=326673&r1=326672&r2=326673&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java
Wed Oct 19 13:11:38 2005
@@ -35,10 +35,10 @@
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.Scheme;
-import org.apache.http.entity.EntityConsumer;
import org.apache.http.executor.HttpRequestExecutor;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
+import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
@@ -73,7 +73,7 @@
HttpMutableRequest request1 = requestfactory.newHttpRequest("GET", "/");
HttpResponse response1 = httpexec.execute(request1, conn);
System.out.println("<< Response: " + response1.getStatusLine());
- System.out.println(EntityConsumer.toString(response1.getEntity()));
+ System.out.println(EntityUtils.toString(response1.getEntity()));
System.out.println("==============");
if (conn.isOpen()) {
System.out.println("Connection kept alive...");
@@ -81,7 +81,7 @@
HttpMutableRequest request2 = requestfactory.newHttpRequest("GET", "/stuff");
HttpResponse response2 = httpexec.execute(request2, conn);
System.out.println("<< Response: " + response2.getStatusLine());
- System.out.println(EntityConsumer.toString(response2.getEntity()));
+ System.out.println(EntityUtils.toString(response2.getEntity()));
System.out.println("==============");
} finally {
conn.close();
Modified: jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpEchoServer.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpEchoServer.java?rev=326673&r1=326672&r2=326673&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpEchoServer.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpEchoServer.java
Wed Oct 19 13:11:38 2005
@@ -46,7 +46,6 @@
import org.apache.http.HttpVersion;
import org.apache.http.MethodNotSupportedException;
import org.apache.http.ProtocolException;
-import org.apache.http.entity.EntityConsumer;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.ConnectionReuseStrategy;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
@@ -56,6 +55,7 @@
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
+import org.apache.http.util.EntityUtils;
/**
* <p>
@@ -102,14 +102,13 @@
buffer.append("<p>Content Chunk-coded: ");
buffer.append(entity.isChunked());
buffer.append("</p>");
- EntityConsumer consume = new EntityConsumer((HttpEntityEnclosingRequest)request);
if (entity.getContentType() != null
&& entity.getContentType().toLowerCase().startsWith("text/"))
{
buffer.append("<p>");
- buffer.append(consume.asString());
+ buffer.append(EntityUtils.toString(entity));
buffer.append("</p>");
} else {
- byte[] raw = consume.asByteArray();
+ byte[] raw = EntityUtils.toByteArray(entity);
buffer.append("<p>");
for (int i = 0; i < raw.length; i++) {
buffer.append(Integer.toHexString(raw[i]).toLowerCase());
Modified: jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpGet.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpGet.java?rev=326673&r1=326672&r2=326673&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpGet.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpGet.java
Wed Oct 19 13:11:38 2005
@@ -34,13 +34,13 @@
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.Scheme;
-import org.apache.http.entity.EntityConsumer;
import org.apache.http.impl.DefaultHttpClientConnection;
import org.apache.http.impl.DefaultHttpParams;
import org.apache.http.impl.io.PlainSocketFactory;
import org.apache.http.io.SocketFactory;
import org.apache.http.message.HttpGet;
import org.apache.http.params.HttpParams;
+import org.apache.http.util.EntityUtils;
/**
* <p>
@@ -85,9 +85,8 @@
// No error response so far.
response = conn.receiveResponse(request);
}
- EntityConsumer body = new EntityConsumer(response);
System.out.println("<< Response: " + response.getStatusLine());
- System.out.println(body.asString());
+ System.out.println(EntityUtils.toString(response.getEntity()));
System.out.println("==============");
}
} finally {
Modified: jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpPost.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpPost.java?rev=326673&r1=326672&r2=326673&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpPost.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpPost.java
Wed Oct 19 13:11:38 2005
@@ -38,7 +38,6 @@
import org.apache.http.HttpResponse;
import org.apache.http.Scheme;
import org.apache.http.entity.ByteArrayEntity;
-import org.apache.http.entity.EntityConsumer;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.DefaultHttpClientConnection;
@@ -47,6 +46,7 @@
import org.apache.http.io.SocketFactory;
import org.apache.http.message.HttpPost;
import org.apache.http.params.HttpParams;
+import org.apache.http.util.EntityUtils;
/**
* <p>
@@ -112,9 +112,8 @@
// No error response so far.
response = conn.receiveResponse(request);
}
- EntityConsumer body = new EntityConsumer(response);
System.out.println("<< Response: " + response.getStatusLine());
- System.out.println(body.asString());
+ System.out.println(EntityUtils.toString(response.getEntity()));
System.out.println("==============");
}
} finally {
Modified: jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/HttpRequestExecutorDemo.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/HttpRequestExecutorDemo.java?rev=326673&r1=326672&r2=326673&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/HttpRequestExecutorDemo.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/HttpRequestExecutorDemo.java
Wed Oct 19 13:11:38 2005
@@ -34,7 +34,6 @@
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.Scheme;
-import org.apache.http.entity.EntityConsumer;
import org.apache.http.executor.HttpRequestExecutor;
import org.apache.http.impl.DefaultHttpClientConnection;
import org.apache.http.impl.DefaultHttpParams;
@@ -48,6 +47,7 @@
import org.apache.http.protocol.RequestExpectContinue;
import org.apache.http.protocol.RequestTargetHost;
import org.apache.http.protocol.RequestUserAgent;
+import org.apache.http.util.EntityUtils;
/**
* <p>
@@ -84,7 +84,7 @@
HttpGet request1 = new HttpGet("/");
HttpResponse response1 = httpexecutor.execute(request1, conn);
System.out.println("<< Response: " + response1.getStatusLine());
- System.out.println(EntityConsumer.toString(response1.getEntity()));
+ System.out.println(EntityUtils.toString(response1.getEntity()));
System.out.println("==============");
if (conn.isOpen()) {
System.out.println("Connection kept alive...");
@@ -92,7 +92,7 @@
HttpGet request2 = new HttpGet("/stuff");
HttpResponse response2 = httpexecutor.execute(request2, conn);
System.out.println("<< Response: " + response2.getStatusLine());
- System.out.println(EntityConsumer.toString(response2.getEntity()));
+ System.out.println(EntityUtils.toString(response2.getEntity()));
System.out.println("==============");
} finally {
conn.close();
Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpEntity.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpEntity.java?rev=326673&r1=326672&r2=326673&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpEntity.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpEntity.java
Wed Oct 19 13:11:38 2005
@@ -35,6 +35,7 @@
import java.io.OutputStream;
import org.apache.http.HttpEntity;
+import org.apache.http.util.EntityUtils;
/**
* <p>
@@ -57,7 +58,7 @@
}
this.source = entity;
if (entity.isChunked() || !entity.isRepeatable() ) {
- this.buffer = EntityConsumer.toByteArray(entity);
+ this.buffer = EntityUtils.toByteArray(entity);
} else {
this.buffer = null;
}
Copied: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/EntityUtils.java
(from r325854, jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/EntityConsumer.java)
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/EntityUtils.java?p2=jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/EntityUtils.java&p1=jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/EntityConsumer.java&r1=325854&r2=326673&rev=326673&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/EntityConsumer.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/EntityUtils.java Wed
Oct 19 13:11:38 2005
@@ -27,7 +27,7 @@
*
*/
-package org.apache.http.entity;
+package org.apache.http.util;
import java.io.IOException;
import java.io.InputStream;
@@ -36,13 +36,7 @@
import org.apache.http.HeaderElement;
import org.apache.http.HttpEntity;
-import org.apache.http.HttpEntityEnclosingRequest;
-import org.apache.http.HttpMessage;
-import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
-import org.apache.http.params.HttpProtocolParams;
-import org.apache.http.util.ByteArrayBuffer;
-import org.apache.http.util.CharArrayBuffer;
/**
* <p>
@@ -53,29 +47,11 @@
*
* @since 4.0
*/
-public class EntityConsumer {
+public class EntityUtils {
- private final HttpMessage message;
- private final HttpEntity entity;
-
- public EntityConsumer(final HttpResponse response) {
- super();
- if (response == null) {
- throw new IllegalArgumentException("HTTP response may not be null");
- }
- this.message = response;
- this.entity = response.getEntity();
- }
-
- public EntityConsumer(final HttpEntityEnclosingRequest request) {
- super();
- if (request == null) {
- throw new IllegalArgumentException("HTTP request may not be null");
- }
- this.message = request;
- this.entity = request.getEntity();
+ private EntityUtils() {
}
-
+
public static byte[] toByteArray(final HttpEntity entity) throws IOException {
if (entity == null) {
throw new IllegalArgumentException("HTTP entity may not be null");
@@ -151,21 +127,6 @@
public static String toString(final HttpEntity entity) throws IOException {
return toString(entity, null);
- }
-
- public byte[] asByteArray() throws IOException {
- if (this.entity == null) {
- return new byte[] {};
- }
- return toByteArray(this.entity);
- }
-
- public String asString() throws IOException {
- if (this.entity == null) {
- return "";
- }
- return toString(this.entity, HttpProtocolParams.getContentCharset(
- this.message.getParams()));
}
}
Modified: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/entity/TestHttpEntities.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/entity/TestHttpEntities.java?rev=326673&r1=326672&r2=326673&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/entity/TestHttpEntities.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/entity/TestHttpEntities.java
Wed Oct 19 13:11:38 2005
@@ -1,7 +1,7 @@
/*
- * $HeadURL: $
- * $Revision: $
- * $Date: $
+ * $HeadURL$
+ * $Revision$
+ * $Date$
*
* ====================================================================
*
|