hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1198871 - in /httpcomponents/httpcore/trunk: ./ httpcore-nio/src/main/java/org/apache/http/nio/entity/ httpcore-nio/src/main/java/org/apache/http/nio/protocol/ httpcore-nio/src/main/java/org/apache/http/nio/util/ httpcore-nio/src/test/java...
Date Mon, 07 Nov 2011 18:50:14 GMT
Author: olegk
Date: Mon Nov  7 18:50:13 2011
New Revision: 1198871

URL: http://svn.apache.org/viewvc?rev=1198871&view=rev
Log:
Deprecated ConsumingNHttpEntity and ProducingNHttpEntity interfaces

Added:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/EntityAsyncContentProducer.java   (contents, props changed)
      - copied, changed from r1181907, httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/NHttpEntityWrapper.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/HttpAsyncContentProducer.java   (contents, props changed)
      - copied, changed from r1181907, httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ProducingNHttpEntity.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/ContentTooLongException.java   (contents, props changed)
      - copied, changed from r1181907, httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentProducer.java
Removed:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/NHttpEntityWrapper.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestNHttpEntityWrapper.java
Modified:
    httpcomponents/httpcore/trunk/.gitignore
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/BufferingNHttpEntity.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntity.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntityTemplate.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ContentInputStream.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NByteArrayEntity.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NFileEntity.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NHttpEntityWrapper.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NStringEntity.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ProducingNHttpEntity.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AbstractAsyncRequestConsumer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AbstractAsyncResponseConsumer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestConsumer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestProducer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseConsumer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseProducer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BufferingAsyncRequestHandler.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/ErrorResponseProducer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestProducer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/ExpandableBuffer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SimpleInputBuffer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncRequestConsumer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncRequestProducer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncResponseConsumer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncResponseProducer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBufferingAsyncRequestHandler.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestErrorResponseProducer.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentProducer.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/EntityTemplate.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestEntityTemplate.java

Modified: httpcomponents/httpcore/trunk/.gitignore
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/.gitignore?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/.gitignore (original)
+++ httpcomponents/httpcore/trunk/.gitignore Mon Nov  7 18:50:13 2011
@@ -2,3 +2,4 @@
 .project
 .settings
 target
+maven-eclipse.xml

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/BufferingNHttpEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/BufferingNHttpEntity.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/BufferingNHttpEntity.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/BufferingNHttpEntity.java Mon Nov  7 18:50:13 2011
@@ -36,6 +36,8 @@ import org.apache.http.annotation.NotThr
 import org.apache.http.entity.HttpEntityWrapper;
 import org.apache.http.nio.ContentDecoder;
 import org.apache.http.nio.IOControl;
+import org.apache.http.nio.protocol.BasicAsyncRequestConsumer;
+import org.apache.http.nio.protocol.BasicAsyncResponseConsumer;
 import org.apache.http.nio.util.ByteBufferAllocator;
 import org.apache.http.nio.util.SimpleInputBuffer;
 
@@ -46,8 +48,11 @@ import org.apache.http.nio.util.SimpleIn
  * {@link HttpEntity#writeTo(OutputStream)}.
  *
  * @since 4.0
+ * 
+ * @deprecated use {@link BasicAsyncRequestConsumer} or {@link BasicAsyncResponseConsumer}
  */
 @NotThreadSafe
+@Deprecated
 public class BufferingNHttpEntity extends HttpEntityWrapper implements
         ConsumingNHttpEntity {
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntity.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntity.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntity.java Mon Nov  7 18:50:13 2011
@@ -32,13 +32,18 @@ import java.io.IOException;
 import org.apache.http.HttpEntity;
 import org.apache.http.nio.ContentDecoder;
 import org.apache.http.nio.IOControl;
+import org.apache.http.nio.protocol.BasicAsyncRequestConsumer;
+import org.apache.http.nio.protocol.BasicAsyncResponseConsumer;
 
 /**
  * A non-blocking {@link HttpEntity} that allows content to be streamed from a
  * {@link ContentDecoder}.
  *
  * @since 4.0
+ * 
+ * @deprecated use {@link BasicAsyncRequestConsumer} or {@link BasicAsyncResponseConsumer}
  */
+@Deprecated
 public interface ConsumingNHttpEntity extends HttpEntity {
 
     /**

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntityTemplate.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntityTemplate.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntityTemplate.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntityTemplate.java Mon Nov  7 18:50:13 2011
@@ -35,14 +35,16 @@ import org.apache.http.HttpEntity;
 import org.apache.http.entity.HttpEntityWrapper;
 import org.apache.http.nio.ContentDecoder;
 import org.apache.http.nio.IOControl;
+import org.apache.http.nio.protocol.BasicAsyncRequestConsumer;
+import org.apache.http.nio.protocol.BasicAsyncResponseConsumer;
 
 /**
  * A {@link ConsumingNHttpEntity} that forwards available content to a
  * {@link ContentListener}.
  *
  * @since 4.0
- *
- * @deprecated use custom {@link ConsumingNHttpEntity}
+ * 
+ * @deprecated use {@link BasicAsyncRequestConsumer} or {@link BasicAsyncResponseConsumer}
  */
 @Deprecated
 public class ConsumingNHttpEntityTemplate

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ContentInputStream.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ContentInputStream.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ContentInputStream.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ContentInputStream.java Mon Nov  7 18:50:13 2011
@@ -51,7 +51,7 @@ public class ContentInputStream extends 
         }
         this.buffer = buffer;
     }
-
+    
     @Override
     public int available() throws IOException {
         if (this.buffer instanceof BufferInfo) {

Copied: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/EntityAsyncContentProducer.java (from r1181907, httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/NHttpEntityWrapper.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/EntityAsyncContentProducer.java?p2=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/EntityAsyncContentProducer.java&p1=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/NHttpEntityWrapper.java&r1=1181907&r2=1198871&rev=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/NHttpEntityWrapper.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/EntityAsyncContentProducer.java Mon Nov  7 18:50:13 2011
@@ -25,57 +25,42 @@
  *
  */
 
-package org.apache.http.nio.protocol;
+package org.apache.http.nio.entity;
 
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
 import java.nio.ByteBuffer;
 import java.nio.channels.Channels;
 import java.nio.channels.ReadableByteChannel;
 
 import org.apache.http.HttpEntity;
-import org.apache.http.entity.HttpEntityWrapper;
+import org.apache.http.annotation.NotThreadSafe;
 import org.apache.http.nio.ContentEncoder;
 import org.apache.http.nio.IOControl;
-import org.apache.http.nio.entity.ProducingNHttpEntity;
 
-class NHttpEntityWrapper extends HttpEntityWrapper implements ProducingNHttpEntity {
+/**
+ *
+ * @since 4.2
+ */
+@NotThreadSafe
+public class EntityAsyncContentProducer implements HttpAsyncContentProducer {
 
+    private final HttpEntity entity;
     private final ByteBuffer buffer;
     private ReadableByteChannel channel;
 
-    public NHttpEntityWrapper(final HttpEntity httpEntity) {
-        super(httpEntity);
+    public EntityAsyncContentProducer(final HttpEntity entity) {
+        super();
+        if (entity == null) {
+            throw new IllegalArgumentException("HTTP entity may not be null");
+        }
+        this.entity = entity;
         this.buffer = ByteBuffer.allocate(4096);
     }
 
-    @Override
-    public InputStream getContent() throws IOException, UnsupportedOperationException {
-        throw new UnsupportedOperationException("Does not support blocking methods");
-    }
-
-    @Override
-    public boolean isStreaming() {
-        return true;
-    }
-
-    @Override
-    public void writeTo(final OutputStream out) throws IOException, UnsupportedOperationException {
-        throw new UnsupportedOperationException("Does not support blocking methods");
-    }
-
-    @Override
-    @Deprecated
-    public void consumeContent() throws IOException {
-        finish();
-    }
-
     public void produceContent(
-            final ContentEncoder encoder,
-            final IOControl ioctrl) throws IOException {
+            final ContentEncoder encoder, final IOControl ioctrl) throws IOException {
         if (this.channel == null) {
-            this.channel = Channels.newChannel(this.wrappedEntity.getContent());
+            this.channel = Channels.newChannel(this.entity.getContent());
         }
         int i = this.channel.read(this.buffer);
         this.buffer.flip();
@@ -84,16 +69,20 @@ class NHttpEntityWrapper extends HttpEnt
         this.buffer.compact();
         if (i == -1 && !buffering) {
             encoder.complete();
-            this.channel.close();
+            close();
         }
     }
 
-    public void finish() throws IOException {
-        if (this.channel != null) {
-            this.channel.close();
-            this.channel = null;
+    public boolean isRepeatable() {
+        return this.entity.isRepeatable();
+    }
+
+    public void close() throws IOException {
+        ReadableByteChannel local = this.channel;
+        this.channel = null;
+        if (local != null) {
+            local.close();
         }
     }
 
 }
-

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/EntityAsyncContentProducer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/EntityAsyncContentProducer.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/EntityAsyncContentProducer.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/EntityAsyncContentProducer.java
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Mon Nov  7 18:50:13 2011
@@ -0,0 +1 @@
+/httpcomponents/httpasyncclient/branches/conn-mgmt-redesign/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/NHttpEntityWrapper.java:1155312-1159070

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/EntityAsyncContentProducer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/HttpAsyncContentProducer.java (from r1181907, httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ProducingNHttpEntity.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/HttpAsyncContentProducer.java?p2=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/HttpAsyncContentProducer.java&p1=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ProducingNHttpEntity.java&r1=1181907&r2=1198871&rev=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ProducingNHttpEntity.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/HttpAsyncContentProducer.java Mon Nov  7 18:50:13 2011
@@ -27,21 +27,16 @@
 
 package org.apache.http.nio.entity;
 
+import java.io.Closeable;
 import java.io.IOException;
 
-import org.apache.http.HttpEntity;
-import org.apache.http.annotation.NotThreadSafe;
 import org.apache.http.nio.ContentEncoder;
 import org.apache.http.nio.IOControl;
 
 /**
- * An {@link HttpEntity} that can stream content out into a
- * {@link ContentEncoder}.
- *
- * @since 4.0
+ * @since 4.2
  */
-@NotThreadSafe
-public interface ProducingNHttpEntity extends HttpEntity {
+public interface HttpAsyncContentProducer extends Closeable {
 
     /**
      * Notification that content should be written to the encoder.
@@ -56,10 +51,7 @@ public interface ProducingNHttpEntity ex
      * @param ioctrl I/O control of the underlying connection.
      */
     void produceContent(ContentEncoder encoder, IOControl ioctrl) throws IOException;
-
-    /**
-     * Notification that any resources allocated for writing can be released.
-     */
-    void finish() throws IOException;
+    
+    boolean isRepeatable();
 
 }

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/HttpAsyncContentProducer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/HttpAsyncContentProducer.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/HttpAsyncContentProducer.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/HttpAsyncContentProducer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NByteArrayEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NByteArrayEntity.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NByteArrayEntity.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NByteArrayEntity.java Mon Nov  7 18:50:13 2011
@@ -45,8 +45,10 @@ import org.apache.http.nio.IOControl;
  *
  * @since 4.0
  */
+@SuppressWarnings("deprecation")
 @NotThreadSafe
-public class NByteArrayEntity extends AbstractHttpEntity implements ProducingNHttpEntity {
+public class NByteArrayEntity extends AbstractHttpEntity 
+                              implements HttpAsyncContentProducer, ProducingNHttpEntity {
 
     private final byte[] b;
     private final int off, len;
@@ -106,10 +108,24 @@ public class NByteArrayEntity extends Ab
         this(b, off, len, null);
     }
 
-    public void finish() {
+    /**
+     * {@inheritDoc}
+     * 
+     * @since 4.2
+     */
+    public void close() {
         this.buf.rewind();
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @deprecated use {@link #close()}
+     */
+    public void finish() {
+        close();
+    }
+
     public void produceContent(final ContentEncoder encoder, final IOControl ioctrl)
             throws IOException {
         encoder.write(this.buf);

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NFileEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NFileEntity.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NFileEntity.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NFileEntity.java Mon Nov  7 18:50:13 2011
@@ -50,8 +50,10 @@ import org.apache.http.nio.IOControl;
  *
  * @since 4.0
  */
+@SuppressWarnings("deprecation")
 @NotThreadSafe
-public class NFileEntity extends AbstractHttpEntity implements ProducingNHttpEntity {
+public class NFileEntity extends AbstractHttpEntity 
+                         implements HttpAsyncContentProducer, ProducingNHttpEntity {
 
     private final File file;
     private FileChannel fileChannel;
@@ -125,12 +127,26 @@ public class NFileEntity extends Abstrac
         this(file, contentType, true);
     }
 
-    public void finish() {
-        try {
-            if(fileChannel != null)
-                fileChannel.close();
-        } catch(IOException ignored) {}
+    /**
+     * {@inheritDoc}
+     * 
+     * @since 4.2
+     */
+    public void close() throws IOException {
+        FileChannel local = fileChannel;
         fileChannel = null;
+        if (local != null) {
+            local.close();
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @deprecated use {@link #close()}
+     */
+    public void finish() throws IOException {
+        close();
     }
 
     public long getContentLength() {
@@ -143,26 +159,27 @@ public class NFileEntity extends Abstrac
 
     public void produceContent(ContentEncoder encoder, IOControl ioctrl)
             throws IOException {
-        if(fileChannel == null) {
+        if (fileChannel == null) {
             FileInputStream in = new FileInputStream(file);
             fileChannel = in.getChannel();
             idx = 0;
         }
 
         long transferred;
-        if(useFileChannels && encoder instanceof FileContentEncoder) {
+        if (useFileChannels && encoder instanceof FileContentEncoder) {
             transferred = ((FileContentEncoder)encoder)
                 .transfer(fileChannel, idx, Long.MAX_VALUE);
         } else {
             transferred = fileChannel.
                 transferTo(idx, Long.MAX_VALUE, new ContentEncoderChannel(encoder));
         }
-
-        if(transferred > 0)
+        if (transferred > 0) {
             idx += transferred;
-
-        if(idx >= fileChannel.size())
+        }
+        if (idx >= fileChannel.size()) {
             encoder.complete();
+            close();
+        }
     }
 
     public boolean isStreaming() {

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NHttpEntityWrapper.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NHttpEntityWrapper.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NHttpEntityWrapper.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NHttpEntityWrapper.java Mon Nov  7 18:50:13 2011
@@ -45,8 +45,11 @@ import org.apache.http.nio.IOControl;
  * entities.
  *
  * @since 4.0
+ * 
+ * @deprecated use {@link EntityAsyncContentProducer}
  */
 @NotThreadSafe
+@Deprecated
 public class NHttpEntityWrapper
     extends HttpEntityWrapper implements ProducingNHttpEntity {
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NStringEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NStringEntity.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NStringEntity.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NStringEntity.java Mon Nov  7 18:50:13 2011
@@ -48,10 +48,15 @@ import org.apache.http.protocol.HTTP;
  * @since 4.0
  *
  */
+@SuppressWarnings("deprecation")
 @NotThreadSafe
 public class NStringEntity extends AbstractHttpEntity implements ProducingNHttpEntity {
 
+    private final byte[] b;
+    private final ByteBuffer buf;
+    @Deprecated
     protected final byte[] content;
+    @Deprecated
     protected final ByteBuffer buffer;
 
     /**
@@ -131,8 +136,10 @@ public class NStringEntity extends Abstr
         if (charset == null) {
             charset = HTTP.DEFAULT_CONTENT_CHARSET;
         }
-        this.content = s.getBytes(charset);
-        this.buffer = ByteBuffer.wrap(this.content);
+        this.b = s.getBytes(charset);
+        this.buf = ByteBuffer.wrap(this.b);
+        this.content = b;
+        this.buffer = this.buf;
         if (contentType != null) {
             setContentType(contentType.toString());
         }
@@ -173,18 +180,33 @@ public class NStringEntity extends Abstr
     }
 
     public long getContentLength() {
-        return this.buffer.limit();
+        return this.b.length;
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @since 4.2
+     */
+    public void close() {
+        this.buf.rewind();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @deprecated use {@link #close()}
+     */
     public void finish() {
-        buffer.rewind();
+        close();
     }
 
-    public void produceContent(ContentEncoder encoder, IOControl ioctrl)
-            throws IOException {
-        encoder.write(buffer);
-        if(!buffer.hasRemaining())
+    public void produceContent(
+            final ContentEncoder encoder, final IOControl ioctrl) throws IOException {
+        encoder.write(this.buf);
+        if (!this.buf.hasRemaining()) {
             encoder.complete();
+        }
     }
 
     public boolean isStreaming() {
@@ -192,14 +214,14 @@ public class NStringEntity extends Abstr
     }
 
     public InputStream getContent() {
-        return new ByteArrayInputStream(content);
+        return new ByteArrayInputStream(this.b);
     }
 
     public void writeTo(final OutputStream outstream) throws IOException {
         if (outstream == null) {
             throw new IllegalArgumentException("Output stream may not be null");
         }
-        outstream.write(content);
+        outstream.write(this.b);
         outstream.flush();
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ProducingNHttpEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ProducingNHttpEntity.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ProducingNHttpEntity.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ProducingNHttpEntity.java Mon Nov  7 18:50:13 2011
@@ -30,17 +30,20 @@ package org.apache.http.nio.entity;
 import java.io.IOException;
 
 import org.apache.http.HttpEntity;
-import org.apache.http.annotation.NotThreadSafe;
 import org.apache.http.nio.ContentEncoder;
 import org.apache.http.nio.IOControl;
+import org.apache.http.nio.protocol.BasicAsyncRequestProducer;
+import org.apache.http.nio.protocol.BasicAsyncResponseProducer;
 
 /**
  * An {@link HttpEntity} that can stream content out into a
  * {@link ContentEncoder}.
  *
  * @since 4.0
+ * 
+ * @deprecated use {@link BasicAsyncRequestProducer} or {@link BasicAsyncResponseProducer}
  */
-@NotThreadSafe
+@Deprecated
 public interface ProducingNHttpEntity extends HttpEntity {
 
     /**

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AbstractAsyncRequestConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AbstractAsyncRequestConsumer.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AbstractAsyncRequestConsumer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AbstractAsyncRequestConsumer.java Mon Nov  7 18:50:13 2011
@@ -28,6 +28,7 @@ package org.apache.http.nio.protocol;
 
 import java.io.IOException;
 
+import org.apache.http.HttpException;
 import org.apache.http.HttpRequest;
 import org.apache.http.annotation.ThreadSafe;
 import org.apache.http.nio.ContentDecoder;
@@ -48,7 +49,7 @@ public abstract class AbstractAsyncReque
         super();
     }
 
-    protected abstract void onRequestReceived(HttpRequest request);
+    protected abstract void onRequestReceived(HttpRequest request) throws HttpException, IOException;
 
     protected abstract void onContentReceived(
             ContentDecoder decoder, IOControl ioctrl) throws IOException;
@@ -57,7 +58,7 @@ public abstract class AbstractAsyncReque
 
     protected abstract void releaseResources();
 
-    public synchronized void requestReceived(HttpRequest request) {
+    public synchronized void requestReceived(HttpRequest request) throws HttpException, IOException {
         onRequestReceived(request);
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AbstractAsyncResponseConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AbstractAsyncResponseConsumer.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AbstractAsyncResponseConsumer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AbstractAsyncResponseConsumer.java Mon Nov  7 18:50:13 2011
@@ -49,7 +49,7 @@ public abstract class AbstractAsyncRespo
         super();
     }
 
-    protected abstract void onResponseReceived(final HttpResponse response);
+    protected abstract void onResponseReceived(final HttpResponse response) throws HttpException, IOException;
 
     protected abstract void onContentReceived(
             final ContentDecoder decoder, final IOControl ioctrl) throws IOException;

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestConsumer.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestConsumer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestConsumer.java Mon Nov  7 18:50:13 2011
@@ -28,16 +28,16 @@ package org.apache.http.nio.protocol;
 
 import java.io.IOException;
 
+import org.apache.http.ContentTooLongException;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpEntityEnclosingRequest;
 import org.apache.http.HttpRequest;
 import org.apache.http.annotation.ThreadSafe;
 import org.apache.http.nio.ContentDecoder;
 import org.apache.http.nio.IOControl;
-import org.apache.http.nio.entity.BufferingNHttpEntity;
-import org.apache.http.nio.entity.ConsumingNHttpEntity;
-import org.apache.http.nio.util.ByteBufferAllocator;
+import org.apache.http.nio.entity.ContentBufferEntity;
 import org.apache.http.nio.util.HeapByteBufferAllocator;
+import org.apache.http.nio.util.SimpleInputBuffer;
 import org.apache.http.protocol.HttpContext;
 
 /**
@@ -46,30 +46,29 @@ import org.apache.http.protocol.HttpCont
 @ThreadSafe
 public class BasicAsyncRequestConsumer extends AbstractAsyncRequestConsumer<HttpRequest> {
 
-    private final ByteBufferAllocator allocator;
     private volatile HttpRequest request;
-    private volatile ConsumingNHttpEntity consumer;
-
-    public BasicAsyncRequestConsumer(final ByteBufferAllocator allocator) {
-        super();
-        if (allocator == null) {
-            throw new IllegalArgumentException("Byte buffer allocator is null");
-        }
-        this.allocator = allocator;
-    }
+    private volatile SimpleInputBuffer buf;
 
     public BasicAsyncRequestConsumer() {
-        this(new HeapByteBufferAllocator());
+        super();
     }
 
     @Override
-    protected void onRequestReceived(final HttpRequest request) {
+    protected void onRequestReceived(final HttpRequest request) throws IOException {
         this.request = request;
         if (request instanceof HttpEntityEnclosingRequest) {
             HttpEntity entity = ((HttpEntityEnclosingRequest) this.request).getEntity();
             if (entity != null) {
-                this.consumer = new BufferingNHttpEntity(entity, this.allocator);
-                ((HttpEntityEnclosingRequest) this.request).setEntity(this.consumer);
+                long len = entity.getContentLength();
+                if (len > Integer.MAX_VALUE) {
+                    throw new ContentTooLongException("Entity content is not long: " + len);
+                }
+                if (len < 0) {
+                    len = 4096;
+                }
+                this.buf = new SimpleInputBuffer((int) len, new HeapByteBufferAllocator());
+                ((HttpEntityEnclosingRequest) this.request).setEntity(
+                        new ContentBufferEntity(entity, this.buf));
             }
         }
     }
@@ -77,16 +76,16 @@ public class BasicAsyncRequestConsumer e
     @Override
     protected void onContentReceived(
             final ContentDecoder decoder, final IOControl ioctrl) throws IOException {
-        if (this.consumer == null) {
-            throw new IllegalArgumentException("Content consumer is null");
+        if (this.buf == null) {
+            throw new IllegalStateException("Content buffer is null");
         }
-        this.consumer.consumeContent(decoder, ioctrl);
+        this.buf.consumeContent(decoder);
     }
 
     @Override
     protected void releaseResources() {
         this.request = null;
-        this.consumer = null;
+        this.buf = null;
     }
 
     @Override

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestProducer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestProducer.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestProducer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestProducer.java Mon Nov  7 18:50:13 2011
@@ -35,7 +35,8 @@ import org.apache.http.HttpRequest;
 import org.apache.http.annotation.ThreadSafe;
 import org.apache.http.nio.ContentEncoder;
 import org.apache.http.nio.IOControl;
-import org.apache.http.nio.entity.ProducingNHttpEntity;
+import org.apache.http.nio.entity.EntityAsyncContentProducer;
+import org.apache.http.nio.entity.HttpAsyncContentProducer;
 import org.apache.http.protocol.HttpContext;
 
 /**
@@ -46,12 +47,12 @@ public class BasicAsyncRequestProducer i
 
     private final HttpHost target;
     private final HttpRequest request;
-    private final ProducingNHttpEntity producer;
+    private final HttpAsyncContentProducer producer;
 
     protected BasicAsyncRequestProducer(
             final HttpHost target,
             final HttpEntityEnclosingRequest request,
-            final ProducingNHttpEntity producer) {
+            final HttpAsyncContentProducer producer) {
         super();
         if (target == null) {
             throw new IllegalArgumentException("HTTP host may not be null");
@@ -59,7 +60,9 @@ public class BasicAsyncRequestProducer i
         if (request == null) {
             throw new IllegalArgumentException("HTTP request may not be null");
         }
-        request.setEntity(producer);
+        if (producer == null) {
+            throw new IllegalArgumentException("HTTP content producer may not be null");
+        }
         this.target = target;
         this.request = request;
         this.producer = producer;
@@ -77,10 +80,10 @@ public class BasicAsyncRequestProducer i
         if (request instanceof HttpEntityEnclosingRequest) {
             HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
             if (entity != null) {
-                if (entity instanceof ProducingNHttpEntity) {
-                    this.producer = (ProducingNHttpEntity) entity;
+                if (entity instanceof HttpAsyncContentProducer) {
+                    this.producer = (HttpAsyncContentProducer) entity;
                 } else {
-                    this.producer = new NHttpEntityWrapper(entity);
+                    this.producer = new EntityAsyncContentProducer(entity);
                 }
             } else {
                 this.producer = null;
@@ -103,7 +106,7 @@ public class BasicAsyncRequestProducer i
         if (this.producer != null) {
             this.producer.produceContent(encoder, ioctrl);
             if (encoder.isCompleted()) {
-                this.producer.finish();
+                this.producer.close();
             }
         }
     }
@@ -115,18 +118,13 @@ public class BasicAsyncRequestProducer i
         return this.producer == null || this.producer.isRepeatable();
     }
 
-    public synchronized void resetRequest() {
-        if (this.producer != null) {
-            try {
-                this.producer.finish();
-            } catch (IOException ignore) {
-            }
-        }
+    public synchronized void resetRequest() throws IOException {
+        this.producer.close();
     }
 
     public synchronized void close() throws IOException {
         if (this.producer != null) {
-            this.producer.finish();
+            this.producer.close();
         }
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseConsumer.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseConsumer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseConsumer.java Mon Nov  7 18:50:13 2011
@@ -28,15 +28,15 @@ package org.apache.http.nio.protocol;
 
 import java.io.IOException;
 
+import org.apache.http.ContentTooLongException;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.annotation.ThreadSafe;
 import org.apache.http.nio.ContentDecoder;
 import org.apache.http.nio.IOControl;
-import org.apache.http.nio.entity.BufferingNHttpEntity;
-import org.apache.http.nio.entity.ConsumingNHttpEntity;
-import org.apache.http.nio.util.ByteBufferAllocator;
+import org.apache.http.nio.entity.ContentBufferEntity;
 import org.apache.http.nio.util.HeapByteBufferAllocator;
+import org.apache.http.nio.util.SimpleInputBuffer;
 import org.apache.http.protocol.HttpContext;
 
 /**
@@ -45,45 +45,43 @@ import org.apache.http.protocol.HttpCont
 @ThreadSafe
 public class BasicAsyncResponseConsumer extends AbstractAsyncResponseConsumer<HttpResponse> {
 
-    private final ByteBufferAllocator allocator;
     private volatile HttpResponse response;
-    private volatile ConsumingNHttpEntity consumer;
-
-    public BasicAsyncResponseConsumer(final ByteBufferAllocator allocator) {
-        super();
-        if (allocator == null) {
-            throw new IllegalArgumentException("Byte buffer allocator is null");
-        }
-        this.allocator = allocator;
-    }
+    private volatile SimpleInputBuffer buf;
 
     public BasicAsyncResponseConsumer() {
-        this(new HeapByteBufferAllocator());
+        super();
     }
 
     @Override
-    protected void onResponseReceived(final HttpResponse response) {
+    protected void onResponseReceived(final HttpResponse response) throws IOException {
         this.response = response;
         HttpEntity entity = this.response.getEntity();
         if (entity != null) {
-            this.consumer = new BufferingNHttpEntity(entity, this.allocator);
-            this.response.setEntity(this.consumer);
+            long len = entity.getContentLength();
+            if (len > Integer.MAX_VALUE) {
+                throw new ContentTooLongException("Entity content is not long: " + len);
+            }
+            if (len < 0) {
+                len = 4096;
+            }
+            this.buf = new SimpleInputBuffer((int) len, new HeapByteBufferAllocator());
+            response.setEntity(new ContentBufferEntity(entity, this.buf));
         }
     }
 
     @Override
     protected void onContentReceived(
             final ContentDecoder decoder, final IOControl ioctrl) throws IOException {
-        if (this.consumer == null) {
-            throw new IllegalArgumentException("Content consumer is null");
+        if (this.buf == null) {
+            throw new IllegalStateException("Content buffer is null");
         }
-        this.consumer.consumeContent(decoder, ioctrl);
+        this.buf.consumeContent(decoder);
     }
 
     @Override
     protected void releaseResources() {
         this.response = null;
-        this.consumer = null;
+        this.buf = null;
     }
 
     @Override

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseProducer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseProducer.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseProducer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseProducer.java Mon Nov  7 18:50:13 2011
@@ -34,7 +34,8 @@ import org.apache.http.HttpResponse;
 import org.apache.http.annotation.ThreadSafe;
 import org.apache.http.nio.ContentEncoder;
 import org.apache.http.nio.IOControl;
-import org.apache.http.nio.entity.ProducingNHttpEntity;
+import org.apache.http.nio.entity.EntityAsyncContentProducer;
+import org.apache.http.nio.entity.HttpAsyncContentProducer;
 import org.apache.http.protocol.HttpContext;
 
 /**
@@ -44,7 +45,21 @@ import org.apache.http.protocol.HttpCont
 public class BasicAsyncResponseProducer implements HttpAsyncResponseProducer {
 
     private final HttpResponse response;
-    private final ProducingNHttpEntity producer;
+    private final HttpAsyncContentProducer producer;
+
+    protected BasicAsyncResponseProducer(
+            final HttpResponse response,
+            final HttpAsyncContentProducer producer) {
+        super();
+        if (response == null) {
+            throw new IllegalArgumentException("HTTP response may not be null");
+        }
+        if (producer == null) {
+            throw new IllegalArgumentException("HTTP content producer may not be null");
+        }
+        this.response = response;
+        this.producer = producer;
+    }
 
     public BasicAsyncResponseProducer(final HttpResponse response) {
         super();
@@ -54,10 +69,10 @@ public class BasicAsyncResponseProducer 
         this.response = response;
         HttpEntity entity = response.getEntity();
         if (entity != null) {
-            if (entity instanceof ProducingNHttpEntity) {
-                this.producer = (ProducingNHttpEntity) entity;
+            if (entity instanceof HttpAsyncContentProducer) {
+                this.producer = (HttpAsyncContentProducer) entity;
             } else {
-                this.producer = new NHttpEntityWrapper(entity);
+                this.producer = new EntityAsyncContentProducer(entity);
             }
         } else {
             this.producer = null;
@@ -73,7 +88,7 @@ public class BasicAsyncResponseProducer 
         if (this.producer != null) {
             this.producer.produceContent(encoder, ioctrl);
             if (encoder.isCompleted()) {
-                this.producer.finish();
+                this.producer.close();
             }
         }
     }
@@ -83,7 +98,7 @@ public class BasicAsyncResponseProducer 
 
     public synchronized void close() throws IOException {
         if (this.producer != null) {
-            this.producer.finish();
+            this.producer.close();
         }
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BufferingAsyncRequestHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BufferingAsyncRequestHandler.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BufferingAsyncRequestHandler.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BufferingAsyncRequestHandler.java Mon Nov  7 18:50:13 2011
@@ -39,8 +39,6 @@ import org.apache.http.ProtocolVersion;
 import org.apache.http.annotation.Immutable;
 import org.apache.http.concurrent.Cancellable;
 import org.apache.http.impl.DefaultHttpResponseFactory;
-import org.apache.http.nio.util.ByteBufferAllocator;
-import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestHandler;
 
@@ -52,12 +50,10 @@ public class BufferingAsyncRequestHandle
 
     private final HttpRequestHandler handler;
     private final HttpResponseFactory responseFactory;
-    private final ByteBufferAllocator allocator;
 
     public BufferingAsyncRequestHandler(
             final HttpRequestHandler handler,
-            final HttpResponseFactory responseFactory,
-            final ByteBufferAllocator allocator) {
+            final HttpResponseFactory responseFactory) {
         super();
         if (handler == null) {
             throw new IllegalArgumentException("Request handler may not be null");
@@ -65,21 +61,17 @@ public class BufferingAsyncRequestHandle
         if (responseFactory == null) {
             throw new IllegalArgumentException("Response factory may not be null");
         }
-        if (allocator == null) {
-            throw new IllegalArgumentException("Byte buffer allocator may not be null");
-        }
         this.handler = handler;
         this.responseFactory = responseFactory;
-        this.allocator = allocator;
     }
 
     public BufferingAsyncRequestHandler(final HttpRequestHandler handler) {
-        this(handler, new DefaultHttpResponseFactory(), new HeapByteBufferAllocator());
+        this(handler, new DefaultHttpResponseFactory());
     }
 
     public HttpAsyncRequestConsumer<HttpRequest> processRequest(final HttpRequest request,
             final HttpContext context) {
-        return new BasicAsyncRequestConsumer(this.allocator);
+        return new BasicAsyncRequestConsumer();
     }
 
     public Cancellable handle(final HttpRequest request, final HttpAsyncResponseTrigger trigger,

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/ErrorResponseProducer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/ErrorResponseProducer.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/ErrorResponseProducer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/ErrorResponseProducer.java Mon Nov  7 18:50:13 2011
@@ -30,13 +30,15 @@ package org.apache.http.nio.protocol;
 import java.io.IOException;
 import java.util.Locale;
 
+import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpVersion;
 import org.apache.http.impl.EnglishReasonPhraseCatalog;
 import org.apache.http.message.BasicHttpResponse;
 import org.apache.http.nio.ContentEncoder;
 import org.apache.http.nio.IOControl;
-import org.apache.http.nio.entity.ProducingNHttpEntity;
+import org.apache.http.nio.entity.EntityAsyncContentProducer;
+import org.apache.http.nio.entity.HttpAsyncContentProducer;
 import org.apache.http.protocol.HTTP;
 import org.apache.http.protocol.HttpContext;
 
@@ -44,18 +46,24 @@ class ErrorResponseProducer implements H
 
     private final HttpVersion version;
     private final int status;
-    private final ProducingNHttpEntity entity;
+    private final HttpEntity entity;
+    private final HttpAsyncContentProducer contentProducer;
     private final boolean keepAlive;
 
     ErrorResponseProducer(
             final HttpVersion version,
             final int status,
-            final ProducingNHttpEntity entity,
+            final HttpEntity entity,
             final boolean keepAlive) {
         super();
         this.version = version;
         this.status = status;
         this.entity = entity;
+        if (entity instanceof HttpAsyncContentProducer) {
+            this.contentProducer = (HttpAsyncContentProducer) entity;
+        } else {
+            this.contentProducer = new EntityAsyncContentProducer(entity);
+        }
         this.keepAlive = keepAlive;
     }
 
@@ -73,14 +81,14 @@ class ErrorResponseProducer implements H
 
     public void produceContent(
             final ContentEncoder encoder, final IOControl ioctrl) throws IOException {
-        this.entity.produceContent(encoder, ioctrl);
+        this.contentProducer.produceContent(encoder, ioctrl);
     }
 
     public void responseCompleted(final HttpContext context) {
     }
 
     public void close() throws IOException {
-        this.entity.finish();
+        this.contentProducer.close();
     }
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestProducer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestProducer.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestProducer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestProducer.java Mon Nov  7 18:50:13 2011
@@ -51,6 +51,6 @@ public interface HttpAsyncRequestProduce
 
     boolean isRepeatable();
 
-    void resetRequest();
+    void resetRequest() throws IOException;
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/ExpandableBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/ExpandableBuffer.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/ExpandableBuffer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/ExpandableBuffer.java Mon Nov  7 18:50:13 2011
@@ -48,9 +48,10 @@ public class ExpandableBuffer implements
     public final static int INPUT_MODE = 0;
     public final static int OUTPUT_MODE = 1;
 
+    private final ByteBufferAllocator allocator;
+
     private int mode;
     protected ByteBuffer buffer = null;
-    private final ByteBufferAllocator allocator;
 
     /**
      * Allocates buffer of the given size using the given allocator.

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SimpleInputBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SimpleInputBuffer.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SimpleInputBuffer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SimpleInputBuffer.java Mon Nov  7 18:50:13 2011
@@ -81,6 +81,7 @@ public class SimpleInputBuffer extends E
         if (isEndOfStream()) {
             return -1;
         }
+        setOutputMode();
         return this.buffer.get() & 0xff;
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncRequestConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncRequestConsumer.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncRequestConsumer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncRequestConsumer.java Mon Nov  7 18:50:13 2011
@@ -63,11 +63,6 @@ public class TestBasicAsyncRequestConsum
     public void tearDown() throws Exception {
     }
 
-    @Test(expected=IllegalArgumentException.class)
-    public void testNullTargetArgConstructor() throws Exception {
-        new BasicAsyncRequestConsumer(null);
-    }
-
     @Test
     public void testRequestProcessing() throws Exception {
         when(request.getEntity()).thenReturn(new StringEntity("stuff"));

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncRequestProducer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncRequestProducer.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncRequestProducer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncRequestProducer.java Mon Nov  7 18:50:13 2011
@@ -36,7 +36,7 @@ import org.apache.http.HttpEntityEnclosi
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.nio.ContentEncoder;
-import org.apache.http.nio.entity.ProducingNHttpEntity;
+import org.apache.http.nio.entity.HttpAsyncContentProducer;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -47,19 +47,15 @@ public class TestBasicAsyncRequestProduc
 
     private BasicAsyncRequestProducer producer;
     private HttpHost target;
-    @Mock private ProducingNHttpEntity entity;
+    @Mock private HttpAsyncContentProducer contentProducer;
     @Mock private HttpEntityEnclosingRequest request;
     @Mock private ContentEncoder encoder;
 
     @Before
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
-
-        when(request.getEntity()).thenReturn(entity);
-
         target = new HttpHost("localhost");
-
-        producer = new BasicAsyncRequestProducer(target, request, entity);
+        producer = new BasicAsyncRequestProducer(target, request, contentProducer);
     }
 
     @After
@@ -68,12 +64,12 @@ public class TestBasicAsyncRequestProduc
 
     @Test(expected=IllegalArgumentException.class)
     public void testNullTarget3ArgConstructor() throws Exception {
-        producer = new BasicAsyncRequestProducer(null, request, entity);
+        producer = new BasicAsyncRequestProducer(null, request, contentProducer);
     }
 
     @Test(expected=IllegalArgumentException.class)
     public void testNullRequest3ArgConstructor() throws Exception {
-        producer = new BasicAsyncRequestProducer(target, null, entity);
+        producer = new BasicAsyncRequestProducer(target, null, contentProducer);
     }
 
     @Test(expected=IllegalArgumentException.class)
@@ -106,7 +102,7 @@ public class TestBasicAsyncRequestProduc
 
         producer.produceContent(encoder,  null);
 
-        verify(entity, times(1)).finish();
+        verify(contentProducer, times(1)).close();
     }
 
     @Test
@@ -115,19 +111,19 @@ public class TestBasicAsyncRequestProduc
 
         producer.produceContent(encoder,  null);
 
-        verify(entity, times(0)).finish();
+        verify(contentProducer, times(0)).close();
     }
 
     @Test
     public void testResetRequest() throws Exception {
         producer.resetRequest();
-        verify(entity, times(1)).finish();
+        verify(contentProducer, times(1)).close();
     }
 
     @Test
     public void testClose() throws Exception {
         producer.close();
-        verify(entity, times(1)).finish();
+        verify(contentProducer, times(1)).close();
     }
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncResponseConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncResponseConsumer.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncResponseConsumer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncResponseConsumer.java Mon Nov  7 18:50:13 2011
@@ -63,11 +63,6 @@ public class TestBasicAsyncResponseConsu
     public void tearDown() throws Exception {
     }
 
-    @Test(expected=IllegalArgumentException.class)
-    public void testNullTargetArgConstructor() throws Exception {
-        new BasicAsyncResponseConsumer(null);
-    }
-
     @Test
     public void testResponseProcessing() throws Exception {
         when(response.getEntity()).thenReturn(new StringEntity("stuff"));

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncResponseProducer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncResponseProducer.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncResponseProducer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncResponseProducer.java Mon Nov  7 18:50:13 2011
@@ -35,7 +35,7 @@ import junit.framework.Assert;
 
 import org.apache.http.HttpResponse;
 import org.apache.http.nio.ContentEncoder;
-import org.apache.http.nio.entity.ProducingNHttpEntity;
+import org.apache.http.nio.entity.HttpAsyncContentProducer;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -45,17 +45,14 @@ import org.mockito.MockitoAnnotations;
 public class TestBasicAsyncResponseProducer {
 
     private BasicAsyncResponseProducer producer;
-    @Mock private ProducingNHttpEntity entity;
+    @Mock private HttpAsyncContentProducer contentProducer;
     @Mock private HttpResponse response;
     @Mock private ContentEncoder encoder;
 
     @Before
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
-
-        when(response.getEntity()).thenReturn(entity);
-
-        producer = new BasicAsyncResponseProducer(response);
+        producer = new BasicAsyncResponseProducer(response, contentProducer);
     }
 
     @After
@@ -80,7 +77,7 @@ public class TestBasicAsyncResponseProdu
 
         producer.produceContent(encoder,  null);
 
-        verify(entity, times(1)).finish();
+        verify(contentProducer, times(1)).close();
     }
 
     @Test
@@ -89,13 +86,13 @@ public class TestBasicAsyncResponseProdu
 
         producer.produceContent(encoder,  null);
 
-        verify(entity, never()).finish();
+        verify(contentProducer, never()).close();
     }
 
     @Test
     public void testClose() throws Exception {
         producer.close();
-        verify(entity, times(1)).finish();
+        verify(contentProducer, times(1)).close();
     }
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBufferingAsyncRequestHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBufferingAsyncRequestHandler.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBufferingAsyncRequestHandler.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBufferingAsyncRequestHandler.java Mon Nov  7 18:50:13 2011
@@ -35,7 +35,6 @@ import org.apache.http.HttpVersion;
 import org.apache.http.concurrent.Cancellable;
 import org.apache.http.impl.DefaultHttpResponseFactory;
 import org.apache.http.message.BasicRequestLine;
-import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.protocol.BasicHttpContext;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestHandler;
@@ -57,7 +56,7 @@ public class TestBufferingAsyncRequestHa
     public void setUp() throws Exception {
         this.requestHandler = Mockito.mock(HttpRequestHandler.class);
         this.asyncRequestHandler = new BufferingAsyncRequestHandler(this.requestHandler,
-                new DefaultHttpResponseFactory(), new HeapByteBufferAllocator());
+                new DefaultHttpResponseFactory());
         this.context = new BasicHttpContext();
         this.request = Mockito.mock(HttpRequest.class);
         this.trigger = Mockito.mock(HttpAsyncResponseTrigger.class);
@@ -71,17 +70,12 @@ public class TestBufferingAsyncRequestHa
     @Test
     public void testInvalidConstruction() throws Exception {
         try {
-            new BufferingAsyncRequestHandler(null, new DefaultHttpResponseFactory(), new HeapByteBufferAllocator());
+            new BufferingAsyncRequestHandler(null, new DefaultHttpResponseFactory());
             Assert.fail("IllegalArgumentException expected");
         } catch (IllegalArgumentException ex) {
         }
         try {
-            new BufferingAsyncRequestHandler(this.requestHandler, null, new HeapByteBufferAllocator());
-            Assert.fail("IllegalArgumentException expected");
-        } catch (IllegalArgumentException ex) {
-        }
-        try {
-            new BufferingAsyncRequestHandler(this.requestHandler, new DefaultHttpResponseFactory(), null);
+            new BufferingAsyncRequestHandler(this.requestHandler, null);
             Assert.fail("IllegalArgumentException expected");
         } catch (IllegalArgumentException ex) {
         }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestErrorResponseProducer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestErrorResponseProducer.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestErrorResponseProducer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestErrorResponseProducer.java Mon Nov  7 18:50:13 2011
@@ -27,14 +27,11 @@
 
 package org.apache.http.nio.protocol;
 
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
 import junit.framework.Assert;
 
+import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpVersion;
-import org.apache.http.nio.entity.ProducingNHttpEntity;
 import org.apache.http.protocol.HTTP;
 import org.junit.After;
 import org.junit.Before;
@@ -45,12 +42,11 @@ import org.mockito.MockitoAnnotations;
 public class TestErrorResponseProducer {
 
     private ErrorResponseProducer erp;
-    @Mock private ProducingNHttpEntity entity;
+    @Mock private HttpEntity entity;
 
     @Before
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
-
     }
 
     @After
@@ -77,13 +73,4 @@ public class TestErrorResponseProducer {
         Assert.assertEquals(200, res.getStatusLine().getStatusCode());
     }
 
-    @Test
-    public void testProduceContent() throws Exception {
-        erp = new ErrorResponseProducer(HttpVersion.HTTP_1_1, 200, entity, true);
-
-        erp.produceContent(null, null);
-
-        verify(entity, times(1)).produceContent(null, null);
-    }
-
 }

Copied: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/ContentTooLongException.java (from r1181907, httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentProducer.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/ContentTooLongException.java?p2=httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/ContentTooLongException.java&p1=httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentProducer.java&r1=1181907&r2=1198871&rev=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentProducer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/ContentTooLongException.java Mon Nov  7 18:50:13 2011
@@ -25,21 +25,26 @@
  *
  */
 
-package org.apache.http.entity;
+package org.apache.http;
 
 import java.io.IOException;
-import java.io.OutputStream;
 
 /**
- * An abstract entity content producer.
- *<p>Content producers are expected to be able to produce their
- * content multiple times</p>
+ * Signals that HTTP entity content is too long.
  *
- * @since 4.0
+ * @since 4.2
  */
-@Deprecated
-public interface ContentProducer {
+public class ContentTooLongException extends IOException {
 
-    void writeTo(OutputStream outstream) throws IOException;
+    private static final long serialVersionUID = -924287689552495383L;
+
+    /**
+     * Creates a new ContentTooLongException with the specified detail message.
+     *
+     * @param message exception message
+     */
+    public ContentTooLongException(String message) {
+        super(message);
+    }
 
 }

Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/ContentTooLongException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/ContentTooLongException.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/ContentTooLongException.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/ContentTooLongException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentProducer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentProducer.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentProducer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentProducer.java Mon Nov  7 18:50:13 2011
@@ -37,7 +37,6 @@ import java.io.OutputStream;
  *
  * @since 4.0
  */
-@Deprecated
 public interface ContentProducer {
 
     void writeTo(OutputStream outstream) throws IOException;

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/EntityTemplate.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/EntityTemplate.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/EntityTemplate.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/EntityTemplate.java Mon Nov  7 18:50:13 2011
@@ -27,21 +27,18 @@
 
 package org.apache.http.entity;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 
-import org.apache.http.HttpEntity;
-
 /**
  * Entity that delegates the process of content generation
  * to a {@link ContentProducer}.
  *
  * @since 4.0
- *
- * @deprecated use custom {@link HttpEntity}
  */
-@Deprecated
 public class EntityTemplate extends AbstractHttpEntity {
 
     private final ContentProducer contentproducer;
@@ -58,8 +55,10 @@ public class EntityTemplate extends Abst
         return -1;
     }
 
-    public InputStream getContent() {
-        throw new UnsupportedOperationException("Entity template does not implement getContent()");
+    public InputStream getContent() throws IOException {
+        ByteArrayOutputStream buf = new ByteArrayOutputStream();
+        writeTo(buf);
+        return new ByteArrayInputStream(buf.toByteArray()); 
     }
 
     public boolean isRepeatable() {

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestEntityTemplate.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestEntityTemplate.java?rev=1198871&r1=1198870&r2=1198871&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestEntityTemplate.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestEntityTemplate.java Mon Nov  7 18:50:13 2011
@@ -29,17 +29,17 @@ package org.apache.http.entity;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 
 import org.apache.http.HttpEntity;
+import org.apache.http.util.EntityUtils;
 import org.junit.Assert;
 import org.junit.Test;
 
 /**
  * Unit tests for {@link EntityTemplate}.
- *
  */
-@Deprecated
 public class TestEntityTemplate {
 
     @Test
@@ -101,12 +101,10 @@ public class TestEntityTemplate {
             }
 
         });
-        try {
-            httpentity.getContent();
-            Assert.fail("UnsupportedOperationException should have been thrown");
-        } catch (UnsupportedOperationException ex) {
-            // expected
-        }
+        InputStream instream = httpentity.getContent();
+        Assert.assertNotNull(instream);
+        String s = EntityUtils.toString(httpentity);
+        Assert.assertEquals("a", s);
     }
 
 }



Mime
View raw message