This is an automated email from the ASF dual-hosted git repository.

johnnyv pushed a commit to branch 2.0.X
in repository https://gitbox.apache.org/repos/asf/mina.git


The following commit(s) were added to refs/heads/2.0.X by this push:
     new 1931add  Backport fix DIRMINA-1104 see 
d3ffb4b779912be1e100b40261877e167ace565c
1931add is described below

commit 1931addc59a4e979c1d9b5fa3a267e961c9b7136
Author: johnnyv <john...@apache.org>
AuthorDate: Sat May 4 11:56:25 2019 -0400

    Backport fix DIRMINA-1104 see d3ffb4b779912be1e100b40261877e167ace565c
---
 .../apache/mina/core/buffer/IoBufferHexDumper.java | 61 ++++++++++------------
 1 file changed, 28 insertions(+), 33 deletions(-)

diff --git 
a/mina-core/src/main/java/org/apache/mina/core/buffer/IoBufferHexDumper.java 
b/mina-core/src/main/java/org/apache/mina/core/buffer/IoBufferHexDumper.java
index 59380b1..4a96bcd 100644
--- a/mina-core/src/main/java/org/apache/mina/core/buffer/IoBufferHexDumper.java
+++ b/mina-core/src/main/java/org/apache/mina/core/buffer/IoBufferHexDumper.java
@@ -63,45 +63,40 @@ class IoBufferHexDumper {
      * @param lengthLimit the limit at which hex dumping will stop
      * @return a hex formatted string representation of the <i>in</i> {@link 
IoBuffer}.
      */
-    public static String getHexdump(IoBuffer in, int lengthLimit) {
-        if (lengthLimit == 0) {
-            throw new IllegalArgumentException("lengthLimit: " + lengthLimit + 
" (expected: 1+)");
-        }
+    public static String getHexdump(IoBuffer in, int length) {
+       if (length < 0) {
+           throw new IllegalArgumentException("length: " + length + " must be 
non-negative number");
+       }
 
-        int limit = in.limit();
-        int pos = in.position();
-        
-        boolean truncate = limit - pos > lengthLimit;
-        int size;
-        if (truncate) {
-            size = lengthLimit;
-        } else {
-            size = limit - pos;
-        }
+       int pos = in.position();
+       int rem = in.limit() - pos;
+       int items = Math.min(rem, length);
 
-        if (size == 0) {
-            return "empty";
-        }
+       if (items == 0) {
+           return "";
+       }
 
-        StringBuilder out = new StringBuilder(size * 3 + 3);
+       int lim = pos + items;
 
-        // fill the first
-        int byteValue = in.get(pos++) & 0xFF;
-        out.append((char) highDigits[byteValue]);
-        out.append((char) lowDigits[byteValue]);
+       StringBuilder out = new StringBuilder((items * 3) + 6);
 
-        // and the others, too
-        for (; pos < limit; ) {
-            out.append(' ');
-            byteValue = in.get(pos++) & 0xFF;
-            out.append((char) highDigits[byteValue]);
-            out.append((char) lowDigits[byteValue]);
-        }
+       /* first sequence to align the spaces */{
+           int byteValue = in.get(pos++) & 0xFF;
+           out.append((char) highDigits[byteValue]);
+           out.append((char) lowDigits[byteValue]);
+       }
 
-        if (truncate) {
-            out.append("...");
-        }
+       /* loop remainder */for (; pos < lim;) {
+           out.append(' ');
+           int byteValue = in.get(pos++) & 0xFF;
+           out.append((char) highDigits[byteValue]);
+           out.append((char) lowDigits[byteValue]);
+       }
+
+       if (items != rem) {
+           out.append("...");
+       }
 
-        return out.toString();
+       return out.toString();
     }
 }
\ No newline at end of file

Reply via email to