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 2018/10/13 12:10:00 UTC
httpcomponents-core git commit: Clarified API contract of
AbstractCharDataConsumer
Repository: httpcomponents-core
Updated Branches:
refs/heads/master f5a66d457 -> bcf09dd05
Clarified API contract of AbstractCharDataConsumer
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/bcf09dd0
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/bcf09dd0
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/bcf09dd0
Branch: refs/heads/master
Commit: bcf09dd0542e7ec90c881ab4f946eabfd32c25c7
Parents: f5a66d4
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Sat Oct 13 14:04:40 2018 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Sat Oct 13 14:04:40 2018 +0200
----------------------------------------------------------------------
.../http/nio/entity/AbstractCharDataConsumer.java | 16 ++++++++++++----
.../http/nio/entity/StringAsyncEntityConsumer.java | 7 ++++++-
.../entity/TestAbstractCharAsyncEntityConsumer.java | 7 ++++++-
3 files changed, 24 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/bcf09dd0/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharDataConsumer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharDataConsumer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharDataConsumer.java
index f8e27a9..bc6b064 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharDataConsumer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharDataConsumer.java
@@ -55,11 +55,19 @@ public abstract class AbstractCharDataConsumer implements AsyncDataConsumer {
private volatile CharsetDecoder charsetDecoder;
/**
- * Triggered to obtain the current capacity of the consumer.
+ * Triggered to obtain the remaining capacity of the consumer.
+ *
+ * @return the total number of bytes this consumer is capable
+ * to process without having to allocate additional resources.
+ */
+ protected abstract int remainingCapacity();
+
+ /**
+ * Triggered to obtain the capacity increment.
*
* @return the number of bytes this consumer is prepared to process.
*/
- protected abstract int capacity();
+ protected abstract int capacityIncrement();
/**
* Triggered to pass incoming data packet to the data consumer.
@@ -82,7 +90,7 @@ public abstract class AbstractCharDataConsumer implements AsyncDataConsumer {
@Override
public final void updateCapacity(final CapacityChannel capacityChannel) throws IOException {
- capacityChannel.update(capacity());
+ capacityChannel.update(capacityIncrement());
}
private void checkResult(final CoderResult result) throws IOException {
@@ -111,7 +119,7 @@ public abstract class AbstractCharDataConsumer implements AsyncDataConsumer {
checkResult(charsetDecoder.decode(src, charbuf, false));
doDecode(false);
}
- return capacity();
+ return remainingCapacity();
}
@Override
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/bcf09dd0/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/StringAsyncEntityConsumer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/StringAsyncEntityConsumer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/StringAsyncEntityConsumer.java
index 1bcda3e..e1070db 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/StringAsyncEntityConsumer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/StringAsyncEntityConsumer.java
@@ -60,11 +60,16 @@ public class StringAsyncEntityConsumer extends AbstractCharAsyncEntityConsumer<S
}
@Override
- protected int capacity() {
+ protected int capacityIncrement() {
return capacityIncrement;
}
@Override
+ protected int remainingCapacity() {
+ return content.capacity() - content.length();
+ }
+
+ @Override
protected final void data(final CharBuffer src, final boolean endOfStream) {
Args.notNull(src, "CharBuffer");
final int chunk = src.remaining();
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/bcf09dd0/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestAbstractCharAsyncEntityConsumer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestAbstractCharAsyncEntityConsumer.java b/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestAbstractCharAsyncEntityConsumer.java
index 54f20cb..779b870 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestAbstractCharAsyncEntityConsumer.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestAbstractCharAsyncEntityConsumer.java
@@ -56,7 +56,12 @@ public class TestAbstractCharAsyncEntityConsumer {
}
@Override
- protected int capacity() {
+ protected int remainingCapacity() {
+ return buffer.capacity() - buffer.length();
+ }
+
+ @Override
+ protected int capacityIncrement() {
return Integer.MAX_VALUE;
}