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/08/14 07:38:29 UTC
[06/11] httpcomponents-core git commit: Access completed state via
methods (better for debugging too.)
Access completed state via methods (better for debugging too.)
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/ba1bf60a
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/ba1bf60a
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/ba1bf60a
Branch: refs/heads/master
Commit: ba1bf60a5bf228f73ad49a6522f49d5aef546949
Parents: 4316c74
Author: Gary Gregory <ga...@gmail.com>
Authored: Mon Aug 13 18:12:21 2018 -0600
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Tue Aug 14 09:27:48 2018 +0200
----------------------------------------------------------------------
.../http/impl/nio/AbstractContentDecoder.java | 29 +++++++++++++++++++-
.../hc/core5/http/impl/nio/ChunkDecoder.java | 6 ++--
.../hc/core5/http/impl/nio/IdentityDecoder.java | 19 +++----------
.../http/impl/nio/LengthDelimitedDecoder.java | 8 +++---
4 files changed, 39 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ba1bf60a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractContentDecoder.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractContentDecoder.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractContentDecoder.java
index eb539a1..ff25a1a 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractContentDecoder.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractContentDecoder.java
@@ -50,7 +50,7 @@ public abstract class AbstractContentDecoder implements ContentDecoder {
final SessionInputBuffer buffer;
final BasicHttpTransportMetrics metrics;
- boolean completed;
+ protected boolean completed;
/**
* Creates an instance of this class.
@@ -91,6 +91,33 @@ public abstract class AbstractContentDecoder implements ContentDecoder {
}
/**
+ * Sets the completed status of this decoder. Normally this is not necessary
+ * (the decoder will automatically complete when the underlying channel
+ * returns EOF). It is useful to mark the decoder as completed if you have
+ * some other means to know all the necessary data has been read and want to
+ * reuse the underlying connection for more messages.
+ *
+ * @param completed the completed status of this decoder.
+ * @since 4.4.11
+ */
+ public void setCompleted(final boolean completed) {
+ this.completed = completed;
+ }
+
+ /**
+ * Sets the completed status of this decoder to true. Normally this is not necessary
+ * (the decoder will automatically complete when the underlying channel
+ * returns EOF). It is useful to mark the decoder as completed if you have
+ * some other means to know all the necessary data has been read and want to
+ * reuse the underlying connection for more messages.
+ *
+ * @since 4.4.11
+ */
+ protected void setCompleted() {
+ this.completed = true;
+ }
+
+ /**
* Reads from the channel to the destination.
*
* @param dst destination.
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ba1bf60a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ChunkDecoder.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ChunkDecoder.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ChunkDecoder.java
index e5e1a95..b56facd 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ChunkDecoder.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ChunkDecoder.java
@@ -222,7 +222,7 @@ public class ChunkDecoder extends AbstractContentDecoder {
} else {
if (!this.buffer.hasData() && this.endOfStream) {
this.state = COMPLETED;
- this.completed = true;
+ setCompleted();
throw new TruncatedChunkException(
"Truncated chunk (expected size: %,d; actual size: %,d)",
chunkSize, pos);
@@ -247,7 +247,7 @@ public class ChunkDecoder extends AbstractContentDecoder {
// Unable to read a footer
if (this.endOfStream) {
this.state = COMPLETED;
- this.completed = true;
+ setCompleted();
}
return totalRead;
}
@@ -259,7 +259,7 @@ public class ChunkDecoder extends AbstractContentDecoder {
parseHeader();
} else {
this.state = COMPLETED;
- this.completed = true;
+ setCompleted();
processFooters();
}
break;
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ba1bf60a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/IdentityDecoder.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/IdentityDecoder.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/IdentityDecoder.java
index 03cfe05..08f03a3 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/IdentityDecoder.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/IdentityDecoder.java
@@ -58,21 +58,10 @@ public class IdentityDecoder extends AbstractContentDecoder implements FileConte
super(channel, buffer, metrics);
}
- /**
- * Sets the completed status of this decoder. Normally this is not necessary
- * (the decoder will automatically complete when the underlying channel
- * returns EOF). It is useful to mark the decoder as completed if you have
- * some other means to know all the necessary data has been read and want to
- * reuse the underlying connection for more messages.
- */
- public void setCompleted(final boolean completed) {
- this.completed = completed;
- }
-
@Override
public int read(final ByteBuffer dst) throws IOException {
Args.notNull(dst, "Byte buffer");
- if (this.completed) {
+ if (isCompleted()) {
return -1;
}
@@ -83,7 +72,7 @@ public class IdentityDecoder extends AbstractContentDecoder implements FileConte
bytesRead = readFromChannel(dst);
}
if (bytesRead == -1) {
- this.completed = true;
+ setCompleted();
}
return bytesRead;
}
@@ -97,7 +86,7 @@ public class IdentityDecoder extends AbstractContentDecoder implements FileConte
if (dst == null) {
return 0;
}
- if (this.completed) {
+ if (isCompleted()) {
return 0;
}
@@ -123,7 +112,7 @@ public class IdentityDecoder extends AbstractContentDecoder implements FileConte
}
}
if (bytesRead == -1) {
- this.completed = true;
+ setCompleted();
}
return bytesRead;
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ba1bf60a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/LengthDelimitedDecoder.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/LengthDelimitedDecoder.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/LengthDelimitedDecoder.java
index 38b6569..1a00718 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/LengthDelimitedDecoder.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/LengthDelimitedDecoder.java
@@ -70,7 +70,7 @@ public class LengthDelimitedDecoder extends AbstractContentDecoder implements Fi
@Override
public int read(final ByteBuffer dst) throws IOException {
Args.notNull(dst, "Byte buffer");
- if (this.completed) {
+ if (isCompleted()) {
return -1;
}
final int chunk = (int) Math.min((this.contentLength - this.len), Integer.MAX_VALUE);
@@ -83,7 +83,7 @@ public class LengthDelimitedDecoder extends AbstractContentDecoder implements Fi
bytesRead = readFromChannel(dst, chunk);
}
if (bytesRead == -1) {
- this.completed = true;
+ setCompleted();
if (this.len < this.contentLength) {
throw new ConnectionClosedException(
"Premature end of Content-Length delimited message body (expected: %,d; received: %,d)",
@@ -109,7 +109,7 @@ public class LengthDelimitedDecoder extends AbstractContentDecoder implements Fi
if (dst == null) {
return 0;
}
- if (this.completed) {
+ if (isCompleted()) {
return -1;
}
@@ -135,7 +135,7 @@ public class LengthDelimitedDecoder extends AbstractContentDecoder implements Fi
}
}
if (bytesRead == -1) {
- this.completed = true;
+ setCompleted();
if (this.len < this.contentLength) {
throw new ConnectionClosedException(
"Premature end of Content-Length delimited message body (expected: %,d; received: %,d)",