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 2017/03/01 10:02:42 UTC

svn commit: r1784894 - in /httpcomponents/httpcore/trunk/httpcore5/src: main/java/org/apache/hc/core5/http/nio/entity/ test/java/org/apache/hc/core5/http/nio/entity/

Author: olegk
Date: Wed Mar  1 10:02:42 2017
New Revision: 1784894

URL: http://svn.apache.org/viewvc?rev=1784894&view=rev
Log:
Abstract async data consumers

Added:
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinDataConsumer.java
      - copied, changed from r1784892, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinAsyncEntityConsumer.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharDataConsumer.java
      - copied, changed from r1784892, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityConsumer.java
Modified:
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinAsyncEntityConsumer.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityConsumer.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/StringAsyncEntityConsumer.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestAbstractBinAsyncEntityConsumer.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestAbstractCharAsyncEntityConsumer.java

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinAsyncEntityConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinAsyncEntityConsumer.java?rev=1784894&r1=1784893&r2=1784894&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinAsyncEntityConsumer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinAsyncEntityConsumer.java Wed Mar  1 10:02:42 2017
@@ -28,26 +28,18 @@ package org.apache.hc.core5.http.nio.ent
 
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
-import java.nio.ByteBuffer;
 import java.nio.charset.UnsupportedCharsetException;
-import java.util.List;
 
 import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.ContentType;
 import org.apache.hc.core5.http.EntityDetails;
-import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpException;
-import org.apache.hc.core5.http.ContentType;
 import org.apache.hc.core5.http.nio.AsyncEntityConsumer;
-import org.apache.hc.core5.http.nio.CapacityChannel;
 import org.apache.hc.core5.util.Args;
 
-public abstract class AbstractBinAsyncEntityConsumer<T> implements AsyncEntityConsumer<T> {
-
-    protected abstract void dataStart(ContentType contentType, FutureCallback<T> resultCallback) throws HttpException, IOException;
-
-    protected abstract void consumeData(ByteBuffer src) throws IOException;
+public abstract class AbstractBinAsyncEntityConsumer<T> extends AbstractBinDataConsumer implements AsyncEntityConsumer<T> {
 
-    protected abstract void dataEnd() throws IOException;
+    protected abstract void start(ContentType contentType, FutureCallback<T> resultCallback) throws HttpException, IOException;
 
     @Override
     public final void streamStart(
@@ -55,27 +47,14 @@ public abstract class AbstractBinAsyncEn
             final FutureCallback<T> resultCallback) throws IOException, HttpException {
         Args.notNull(resultCallback, "Result callback");
         try {
-            final String contentType = entityDetails.getContentType();
-            dataStart(contentType != null ? ContentType.parse(contentType) : null, resultCallback);
+            final ContentType contentType = entityDetails != null ? ContentType.parse(entityDetails.getContentType()) : null;
+            start(contentType, resultCallback);
+            if (entityDetails == null) {
+                completed();
+            }
         } catch (UnsupportedCharsetException ex) {
             throw new UnsupportedEncodingException(ex.getMessage());
         }
     }
 
-    @Override
-    public final void updateCapacity(final CapacityChannel capacityChannel) throws IOException {
-        capacityChannel.update(Integer.MAX_VALUE);
-    }
-
-    @Override
-    public final int consume(final ByteBuffer src) throws IOException {
-        consumeData(src);
-        return Integer.MAX_VALUE;
-    }
-
-    @Override
-    public final void streamEnd(final List<? extends Header> trailers) throws IOException {
-        dataEnd();
-    }
-
 }

Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinDataConsumer.java (from r1784892, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinAsyncEntityConsumer.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinDataConsumer.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinDataConsumer.java&p1=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinAsyncEntityConsumer.java&r1=1784892&r2=1784894&rev=1784894&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinAsyncEntityConsumer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinDataConsumer.java Wed Mar  1 10:02:42 2017
@@ -27,55 +27,39 @@
 package org.apache.hc.core5.http.nio.entity;
 
 import java.io.IOException;
-import java.io.UnsupportedEncodingException;
 import java.nio.ByteBuffer;
-import java.nio.charset.UnsupportedCharsetException;
 import java.util.List;
 
-import org.apache.hc.core5.concurrent.FutureCallback;
-import org.apache.hc.core5.http.EntityDetails;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpException;
-import org.apache.hc.core5.http.ContentType;
-import org.apache.hc.core5.http.nio.AsyncEntityConsumer;
+import org.apache.hc.core5.http.nio.AsyncDataConsumer;
 import org.apache.hc.core5.http.nio.CapacityChannel;
-import org.apache.hc.core5.util.Args;
 
-public abstract class AbstractBinAsyncEntityConsumer<T> implements AsyncEntityConsumer<T> {
+public abstract class AbstractBinDataConsumer implements AsyncDataConsumer {
 
-    protected abstract void dataStart(ContentType contentType, FutureCallback<T> resultCallback) throws HttpException, IOException;
+    private static final ByteBuffer EMPTY = ByteBuffer.wrap(new byte[0]);
 
-    protected abstract void consumeData(ByteBuffer src) throws IOException;
+    protected abstract int capacity();
 
-    protected abstract void dataEnd() throws IOException;
+    protected abstract void data(ByteBuffer data, boolean endOfStream) throws IOException;
 
-    @Override
-    public final void streamStart(
-            final EntityDetails entityDetails,
-            final FutureCallback<T> resultCallback) throws IOException, HttpException {
-        Args.notNull(resultCallback, "Result callback");
-        try {
-            final String contentType = entityDetails.getContentType();
-            dataStart(contentType != null ? ContentType.parse(contentType) : null, resultCallback);
-        } catch (UnsupportedCharsetException ex) {
-            throw new UnsupportedEncodingException(ex.getMessage());
-        }
-    }
+    protected abstract void completed() throws IOException;
 
     @Override
     public final void updateCapacity(final CapacityChannel capacityChannel) throws IOException {
-        capacityChannel.update(Integer.MAX_VALUE);
+        capacityChannel.update(capacity());
     }
 
     @Override
     public final int consume(final ByteBuffer src) throws IOException {
-        consumeData(src);
-        return Integer.MAX_VALUE;
+        data(src, false);
+        return capacity();
     }
 
     @Override
-    public final void streamEnd(final List<? extends Header> trailers) throws IOException {
-        dataEnd();
+    public final void streamEnd(final List<? extends Header> trailers) throws HttpException, IOException {
+        data(EMPTY, true);
+        completed();
     }
 
-}
+}
\ No newline at end of file

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityConsumer.java?rev=1784894&r1=1784893&r2=1784894&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityConsumer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityConsumer.java Wed Mar  1 10:02:42 2017
@@ -28,39 +28,23 @@ package org.apache.hc.core5.http.nio.ent
 
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
 import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CoderResult;
 import java.nio.charset.StandardCharsets;
 import java.nio.charset.UnsupportedCharsetException;
-import java.util.List;
 
 import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.ContentType;
 import org.apache.hc.core5.http.EntityDetails;
-import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpException;
-import org.apache.hc.core5.http.ContentType;
 import org.apache.hc.core5.http.nio.AsyncEntityConsumer;
 import org.apache.hc.core5.util.Args;
 
 /**
  * @since 5.0
  */
-public abstract class AbstractCharAsyncEntityConsumer<T> implements AsyncEntityConsumer<T> {
-
-    private static final ByteBuffer EMPTY = ByteBuffer.wrap(new byte[0]);
-
-    private volatile ContentType contentType;
-    private volatile CharsetDecoder charsetDecoder;
-    private volatile CharBuffer charbuf;
+public abstract class AbstractCharAsyncEntityConsumer<T> extends AbstractCharDataConsumer implements AsyncEntityConsumer<T> {
 
-    protected abstract void dataStart(ContentType contentType, FutureCallback<T> resultCallback) throws HttpException, IOException;
-
-    protected abstract void consumeData(CharBuffer src) throws IOException;
-
-    protected abstract void dataEnd() throws IOException;
+    protected abstract void start(ContentType contentType, FutureCallback<T> resultCallback) throws HttpException, IOException;
 
     @Override
     public final void streamStart(
@@ -68,60 +52,19 @@ public abstract class AbstractCharAsyncE
             final FutureCallback<T> resultCallback) throws IOException, HttpException {
         Args.notNull(resultCallback, "Result callback");
         try {
-            this.contentType = entityDetails != null ? ContentType.parse(entityDetails.getContentType()) : null;
-            dataStart(this.contentType, resultCallback);
-        } catch (UnsupportedCharsetException ex) {
-            throw new UnsupportedEncodingException(ex.getMessage());
-        }
-    }
-
-    private void checkResult(final CoderResult result) throws IOException {
-        if (result.isError()) {
-            result.throwException();
-        }
-    }
-
-    private void doDecode() throws IOException {
-        charbuf.flip();
-        final int chunk = charbuf.remaining();
-        if (chunk > 0) {
-            consumeData(charbuf);
-        }
-        charbuf.clear();
-    }
-
-    @Override
-    public final int consume(final ByteBuffer src) throws IOException {
-        Args.notNull(src, "ByteBuffer");
-        if (charsetDecoder == null) {
+            final ContentType contentType = entityDetails != null ? ContentType.parse(entityDetails.getContentType()) : null;
             Charset charset = contentType != null ? contentType.getCharset() : null;
             if (charset == null) {
                 charset = StandardCharsets.US_ASCII;
             }
-            charsetDecoder = charset.newDecoder();
-        }
-        if (charbuf == null) {
-            charbuf = CharBuffer.allocate(2048);
-        }
-        while (src.hasRemaining()) {
-            checkResult(charsetDecoder.decode(src, charbuf, false));
-            doDecode();
-        }
-        return Integer.MAX_VALUE;
-    }
-
-    @Override
-    public final void streamEnd(final List<? extends Header> trailers) throws IOException {
-        if (charsetDecoder != null) {
-            if (charbuf == null) {
-                charbuf = CharBuffer.allocate(512);
+            setCharset(charset);
+            start(contentType, resultCallback);
+            if (entityDetails == null) {
+                completed();
             }
-            checkResult(charsetDecoder.decode(EMPTY, charbuf, true));
-            doDecode();
-            checkResult(charsetDecoder.flush(charbuf));
-            doDecode();
+        } catch (UnsupportedCharsetException ex) {
+            throw new UnsupportedEncodingException(ex.getMessage());
         }
-        dataEnd();
     }
 
 }

Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharDataConsumer.java (from r1784892, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityConsumer.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharDataConsumer.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharDataConsumer.java&p1=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityConsumer.java&r1=1784892&r2=1784894&rev=1784894&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityConsumer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharDataConsumer.java Wed Mar  1 10:02:42 2017
@@ -27,52 +27,42 @@
 package org.apache.hc.core5.http.nio.entity;
 
 import java.io.IOException;
-import java.io.UnsupportedEncodingException;
 import java.nio.ByteBuffer;
 import java.nio.CharBuffer;
 import java.nio.charset.Charset;
 import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CoderResult;
 import java.nio.charset.StandardCharsets;
-import java.nio.charset.UnsupportedCharsetException;
 import java.util.List;
 
-import org.apache.hc.core5.concurrent.FutureCallback;
-import org.apache.hc.core5.http.EntityDetails;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpException;
-import org.apache.hc.core5.http.ContentType;
-import org.apache.hc.core5.http.nio.AsyncEntityConsumer;
-import org.apache.hc.core5.util.Args;
-
-/**
- * @since 5.0
- */
-public abstract class AbstractCharAsyncEntityConsumer<T> implements AsyncEntityConsumer<T> {
+import org.apache.hc.core5.http.nio.AsyncDataConsumer;
+import org.apache.hc.core5.http.nio.CapacityChannel;
 
-    private static final ByteBuffer EMPTY = ByteBuffer.wrap(new byte[0]);
+public abstract class AbstractCharDataConsumer implements AsyncDataConsumer {
 
-    private volatile ContentType contentType;
+    private static final ByteBuffer EMPTY_BIN = ByteBuffer.wrap(new byte[0]);
+
+    private final CharBuffer charbuf = CharBuffer.allocate(8192);
+
+    private volatile Charset charset = StandardCharsets.US_ASCII;
     private volatile CharsetDecoder charsetDecoder;
-    private volatile CharBuffer charbuf;
 
-    protected abstract void dataStart(ContentType contentType, FutureCallback<T> resultCallback) throws HttpException, IOException;
+    protected abstract int capacity();
 
-    protected abstract void consumeData(CharBuffer src) throws IOException;
+    protected abstract void data(CharBuffer data, boolean endOfStream) throws IOException;
 
-    protected abstract void dataEnd() throws IOException;
+    protected abstract void completed() throws IOException;
+
+    protected final void setCharset(final Charset charset) {
+        this.charset = charset != null ? charset : StandardCharsets.US_ASCII;
+        this.charsetDecoder = null;
+    }
 
     @Override
-    public final void streamStart(
-            final EntityDetails entityDetails,
-            final FutureCallback<T> resultCallback) throws IOException, HttpException {
-        Args.notNull(resultCallback, "Result callback");
-        try {
-            this.contentType = entityDetails != null ? ContentType.parse(entityDetails.getContentType()) : null;
-            dataStart(this.contentType, resultCallback);
-        } catch (UnsupportedCharsetException ex) {
-            throw new UnsupportedEncodingException(ex.getMessage());
-        }
+    public final void updateCapacity(final CapacityChannel capacityChannel) throws IOException {
+        capacityChannel.update(capacity());
     }
 
     private void checkResult(final CoderResult result) throws IOException {
@@ -81,47 +71,40 @@ public abstract class AbstractCharAsyncE
         }
     }
 
-    private void doDecode() throws IOException {
+    private void doDecode(final boolean endOfStream) throws IOException {
         charbuf.flip();
         final int chunk = charbuf.remaining();
         if (chunk > 0) {
-            consumeData(charbuf);
+            data(charbuf, endOfStream);
         }
         charbuf.clear();
     }
 
-    @Override
-    public final int consume(final ByteBuffer src) throws IOException {
-        Args.notNull(src, "ByteBuffer");
+    private CharsetDecoder getCharsetDecoder() {
         if (charsetDecoder == null) {
-            Charset charset = contentType != null ? contentType.getCharset() : null;
-            if (charset == null) {
-                charset = StandardCharsets.US_ASCII;
-            }
-            charsetDecoder = charset.newDecoder();
-        }
-        if (charbuf == null) {
-            charbuf = CharBuffer.allocate(2048);
+            charsetDecoder = charset != null ? charset.newDecoder() : StandardCharsets.US_ASCII.newDecoder();
         }
+        return charsetDecoder;
+    }
+
+    @Override
+    public final int consume(final ByteBuffer src) throws IOException {
+        final CharsetDecoder charsetDecoder = getCharsetDecoder();
         while (src.hasRemaining()) {
             checkResult(charsetDecoder.decode(src, charbuf, false));
-            doDecode();
+            doDecode(false);
         }
-        return Integer.MAX_VALUE;
+        return capacity();
     }
 
     @Override
-    public final void streamEnd(final List<? extends Header> trailers) throws IOException {
-        if (charsetDecoder != null) {
-            if (charbuf == null) {
-                charbuf = CharBuffer.allocate(512);
-            }
-            checkResult(charsetDecoder.decode(EMPTY, charbuf, true));
-            doDecode();
-            checkResult(charsetDecoder.flush(charbuf));
-            doDecode();
-        }
-        dataEnd();
+    public final void streamEnd(final List<? extends Header> trailers) throws HttpException, IOException {
+        final CharsetDecoder charsetDecoder = getCharsetDecoder();
+        checkResult(charsetDecoder.decode(EMPTY_BIN, charbuf, true));
+        doDecode(false);
+        checkResult(charsetDecoder.flush(charbuf));
+        doDecode(true);
+        completed();
     }
 
-}
+}
\ No newline at end of file

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/StringAsyncEntityConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/StringAsyncEntityConsumer.java?rev=1784894&r1=1784893&r2=1784894&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/StringAsyncEntityConsumer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/StringAsyncEntityConsumer.java Wed Mar  1 10:02:42 2017
@@ -31,9 +31,8 @@ import java.nio.CharBuffer;
 import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.hc.core5.concurrent.FutureCallback;
-import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.ContentType;
-import org.apache.hc.core5.http.nio.CapacityChannel;
+import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.CharArrayBuffer;
 
@@ -57,18 +56,18 @@ public class StringAsyncEntityConsumer e
     }
 
     @Override
-    public void updateCapacity(final CapacityChannel capacityChannel) throws IOException {
-        capacityChannel.update(capacityIncrement);
+    protected final void start(
+            final ContentType contentType, final FutureCallback<String> resultCallback) throws HttpException, IOException {
+        this.resultCallback = resultCallback;
     }
 
     @Override
-    protected void dataStart(
-            final ContentType contentType, final FutureCallback<String> resultCallback) throws HttpException, IOException {
-        this.resultCallback = resultCallback;
+    protected int capacity() {
+        return capacityIncrement;
     }
 
     @Override
-    protected void consumeData(final CharBuffer src) {
+    protected final void data(final CharBuffer src, final boolean endOfStream) {
         Args.notNull(src, "CharBuffer");
         final int chunk = src.remaining();
         content.ensureCapacity(chunk);
@@ -77,14 +76,14 @@ public class StringAsyncEntityConsumer e
     }
 
     @Override
-    protected void dataEnd() throws IOException {
+    protected void completed() throws IOException {
         if (resultCallback != null) {
             resultCallback.completed(content.toString());
         }
     }
 
     @Override
-    public void failed(final Exception cause) {
+    public final void failed(final Exception cause) {
         if (exception.compareAndSet(null, cause)) {
             if (resultCallback != null) {
                 resultCallback.failed(cause);

Modified: httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestAbstractBinAsyncEntityConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestAbstractBinAsyncEntityConsumer.java?rev=1784894&r1=1784893&r2=1784894&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestAbstractBinAsyncEntityConsumer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestAbstractBinAsyncEntityConsumer.java Wed Mar  1 10:02:42 2017
@@ -32,10 +32,10 @@ import java.nio.ByteBuffer;
 import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.ContentType;
 import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.impl.BasicEntityDetails;
 import org.apache.hc.core5.http.impl.nio.ExpandableBuffer;
-import org.apache.hc.core5.http.ContentType;
 import org.apache.hc.core5.http.nio.AsyncEntityConsumer;
 import org.junit.Assert;
 import org.junit.Test;
@@ -76,19 +76,24 @@ public class TestAbstractBinAsyncEntityC
         }
 
         @Override
-        protected void dataStart(
+        protected void start(
                 final ContentType contentType,
                 final FutureCallback<byte[]> resultCallback) throws HttpException, IOException {
             this.resultCallback = resultCallback;
         }
 
         @Override
-        protected void consumeData(final ByteBuffer src) throws IOException {
+        protected int capacity() {
+            return Integer.MAX_VALUE;
+        }
+
+        @Override
+        protected void data(final ByteBuffer src, final boolean endOfStream) throws IOException {
             buffer.write(src);
         }
 
         @Override
-        protected void dataEnd() throws IOException {
+        protected void completed() throws IOException {
             content = buffer.toByteArray();
             if (resultCallback != null) {
                 resultCallback.completed(content);

Modified: httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestAbstractCharAsyncEntityConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestAbstractCharAsyncEntityConsumer.java?rev=1784894&r1=1784893&r2=1784894&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestAbstractCharAsyncEntityConsumer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestAbstractCharAsyncEntityConsumer.java Wed Mar  1 10:02:42 2017
@@ -33,11 +33,10 @@ import java.nio.CharBuffer;
 import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.ContentType;
 import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.impl.BasicEntityDetails;
-import org.apache.hc.core5.http.ContentType;
 import org.apache.hc.core5.http.nio.AsyncEntityConsumer;
-import org.apache.hc.core5.http.nio.CapacityChannel;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -55,24 +54,24 @@ public class TestAbstractCharAsyncEntity
         }
 
         @Override
-        protected void dataStart(
+        protected void start(
                 final ContentType contentType,
                 final FutureCallback<String> resultCallback) throws HttpException, IOException {
             this.resultCallback = resultCallback;
         }
 
         @Override
-        public void updateCapacity(final CapacityChannel capacityChannel) throws IOException {
-            capacityChannel.update(Integer.MAX_VALUE);
+        protected int capacity() {
+            return Integer.MAX_VALUE;
         }
 
         @Override
-        protected void consumeData(final CharBuffer src) throws IOException {
+        protected void data(final CharBuffer src, final boolean endOfStream) throws IOException {
             buffer.append(src);
         }
 
         @Override
-        protected void dataEnd() throws IOException {
+        protected void completed() throws IOException {
             content = buffer.toString();
             if (resultCallback != null) {
                 resultCallback.completed(content);