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:51:47 UTC

[12/12] httpcomponents-core git commit: Better formatting of exception message.

Better formatting of exception message.


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/9bfbbb41
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/9bfbbb41
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/9bfbbb41

Branch: refs/heads/4.4.x
Commit: 9bfbbb41f0d5db4e499ace6a50300560e19a8fad
Parents: 4592ae6
Author: Gary Gregory <ga...@gmail.com>
Authored: Mon Aug 13 21:53:03 2018 -0600
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Tue Aug 14 09:49:35 2018 +0200

----------------------------------------------------------------------
 .../apache/http/impl/nio/codecs/IdentityDecoder.java    |  4 ++--
 .../http/impl/nio/codecs/LengthDelimitedDecoder.java    |  4 ++--
 .../http/nio/protocol/BasicAsyncRequestConsumer.java    |  2 +-
 .../http/nio/protocol/BasicAsyncResponseConsumer.java   |  2 +-
 .../java/org/apache/http/ContentTooLongException.java   | 12 ++++++++++++
 5 files changed, 18 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/9bfbbb41/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/IdentityDecoder.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/IdentityDecoder.java b/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/IdentityDecoder.java
index 461263a..e948452 100644
--- a/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/IdentityDecoder.java
+++ b/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/IdentityDecoder.java
@@ -98,8 +98,8 @@ public class IdentityDecoder extends AbstractContentDecoder
         } else {
             if (this.channel.isOpen()) {
                 if (position > dst.size()) {
-                    throw new IOException("Position past end of file [" + position +
-                            " > " + dst.size() + "]");
+                    throw new IOException(String.format("Position past end of file [%,d > %,d]",
+                                    position, dst.size()));
                 }
                 bytesRead = dst.transferFrom(this.channel, position, count);
                 if (count > 0 && bytesRead == 0) {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/9bfbbb41/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedDecoder.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedDecoder.java b/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedDecoder.java
index 2df2f45..93d2065 100644
--- a/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedDecoder.java
+++ b/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedDecoder.java
@@ -121,8 +121,8 @@ public class LengthDelimitedDecoder extends AbstractContentDecoder
         } else {
             if (this.channel.isOpen()) {
                 if (position > dst.size()) {
-                    throw new IOException("Position past end of file [" + position +
-                            " > " + dst.size() + "]");
+                    throw new IOException(String.format("Position past end of file [%,d > %,d]",
+                                    position, dst.size()));
                 }
                 bytesRead = dst.transferFrom(this.channel, position, count < chunk ? count : chunk);
             } else {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/9bfbbb41/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestConsumer.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestConsumer.java b/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestConsumer.java
index 9508506..9524169 100644
--- a/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestConsumer.java
+++ b/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestConsumer.java
@@ -69,7 +69,7 @@ public class BasicAsyncRequestConsumer extends AbstractAsyncRequestConsumer<Http
             final HttpEntity entity, final ContentType contentType) throws IOException {
         long len = entity.getContentLength();
         if (len > Integer.MAX_VALUE) {
-            throw new ContentTooLongException("Entity content is too long: " + len);
+            throw new ContentTooLongException("Entity content is too long: %,d", len);
         }
         if (len < 0) {
             len = 4096;

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/9bfbbb41/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseConsumer.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseConsumer.java b/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseConsumer.java
index a42aaa6..66fd4e3 100644
--- a/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseConsumer.java
+++ b/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseConsumer.java
@@ -68,7 +68,7 @@ public class BasicAsyncResponseConsumer extends AbstractAsyncResponseConsumer<Ht
             final HttpEntity entity, final ContentType contentType) throws IOException {
         long len = entity.getContentLength();
         if (len > Integer.MAX_VALUE) {
-            throw new ContentTooLongException("Entity content is too long: " + len);
+            throw new ContentTooLongException("Entity content is too long: %,d", len);
         }
         if (len < 0) {
             len = 4096;

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/9bfbbb41/httpcore/src/main/java/org/apache/http/ContentTooLongException.java
----------------------------------------------------------------------
diff --git a/httpcore/src/main/java/org/apache/http/ContentTooLongException.java b/httpcore/src/main/java/org/apache/http/ContentTooLongException.java
index f7020ac..c8ca10f 100644
--- a/httpcore/src/main/java/org/apache/http/ContentTooLongException.java
+++ b/httpcore/src/main/java/org/apache/http/ContentTooLongException.java
@@ -47,4 +47,16 @@ public class ContentTooLongException extends IOException {
         super(message);
     }
 
+    /**
+     * Constructs a new ContentTooLongException with the specified detail message.
+     *
+     * @param format The exception detail message format; see {@link String#format(String, Object...)}.
+     * @param args The exception detail message arguments; see {@link String#format(String, Object...)}.
+     *
+     * @since 4.4.11
+     */
+    public ContentTooLongException(final String format, final Object... args) {
+        super(HttpException.clean(String.format(format, args)));
+    }
+
 }