Skip to content

Commit

Permalink
Backport fix DIRMINA-1104 see d3ffb4b
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-valliere committed May 4, 2019
1 parent 3e57e7f commit 1931add
Showing 1 changed file with 28 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 1931add

Please sign in to comment.