You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2011/07/22 16:28:39 UTC
svn commit: r1149616 - in
/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods:
HttpAsyncMethods.java ZeroCopyConsumer.java
Author: olegk
Date: Fri Jul 22 14:28:38 2011
New Revision: 1149616
URL: http://svn.apache.org/viewvc?rev=1149616&view=rev
Log:
Added support for zero copy producers / consumers to HttpAsyncMethods
Modified:
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/HttpAsyncMethods.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/ZeroCopyConsumer.java
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/HttpAsyncMethods.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/HttpAsyncMethods.java?rev=1149616&r1=1149615&r2=1149616&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/HttpAsyncMethods.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/HttpAsyncMethods.java Fri Jul 22 14:28:38 2011
@@ -26,6 +26,7 @@
*/
package org.apache.http.nio.client.methods;
+import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URI;
@@ -189,8 +190,47 @@ public final class HttpAsyncMethods {
return createPut(URI.create(requestURI), content, contentType);
}
+ public static HttpAsyncRequestProducer createZeroCopyPost(
+ final URI requestURI,
+ final File content,
+ final String contentType) {
+ return new ZeroCopyPost(requestURI, content, contentType);
+ }
+
+ public static HttpAsyncRequestProducer createZeroCopyPost(
+ final String requestURI,
+ final File content,
+ final String contentType) {
+ return new ZeroCopyPost(URI.create(requestURI), content, contentType);
+ }
+
+ public static HttpAsyncRequestProducer createZeroCopyPut(
+ final URI requestURI,
+ final File content,
+ final String contentType) {
+ return new ZeroCopyPut(requestURI, content, contentType);
+ }
+
+ public static HttpAsyncRequestProducer createZeroCopyPut(
+ final String requestURI,
+ final File content,
+ final String contentType) {
+ return new ZeroCopyPut(URI.create(requestURI), content, contentType);
+ }
+
public static HttpAsyncResponseConsumer<HttpResponse> createConsumer() {
return new BasicHttpAsyncResponseConsumer();
}
+ public static HttpAsyncResponseConsumer<HttpResponse> createZeroCopyConsumer(final File file) {
+ return new ZeroCopyConsumer<HttpResponse>(file) {
+
+ @Override
+ protected HttpResponse process(final HttpResponse response, final File file) throws Exception {
+ return response;
+ }
+
+ };
+ }
+
}
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/ZeroCopyConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/ZeroCopyConsumer.java?rev=1149616&r1=1149615&r2=1149616&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/ZeroCopyConsumer.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/ZeroCopyConsumer.java Fri Jul 22 14:28:38 2011
@@ -32,10 +32,12 @@ import java.io.IOException;
import java.nio.channels.FileChannel;
import org.apache.http.HttpResponse;
+import org.apache.http.entity.FileEntity;
import org.apache.http.nio.ContentDecoder;
import org.apache.http.nio.ContentDecoderChannel;
import org.apache.http.nio.FileContentDecoder;
import org.apache.http.nio.IOControl;
+import org.apache.http.protocol.HTTP;
public abstract class ZeroCopyConsumer<T> extends AbstractHttpAsyncResponseConsumer<T> {
@@ -87,6 +89,9 @@ public abstract class ZeroCopyConsumer<T
@Override
protected T buildResult() throws Exception {
+ FileEntity entity = new FileEntity(this.file, null);
+ entity.setContentType(this.response.getFirstHeader(HTTP.CONTENT_TYPE));
+ this.response.setEntity(entity);
return process(this.response, this.file);
}