You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by jv...@apache.org on 2013/06/19 10:14:29 UTC
git commit: DIRMINA-946 fix for the dumping function (it was crashing
with ByteBuffers that are not backed by an array or that are readonly)
Updated Branches:
refs/heads/trunk d6f7ad503 -> ff21d87f9
DIRMINA-946 fix for the dumping function (it was crashing with ByteBuffers that are not backed by an array or that are readonly)
Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/ff21d87f
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/ff21d87f
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/ff21d87f
Branch: refs/heads/trunk
Commit: ff21d87f9f35fb00f8a097a8a4d083b3c4fa09aa
Parents: d6f7ad5
Author: Raphaël P. Barazzutti <ra...@gmail.com>
Authored: Wed Jun 19 03:01:01 2013 +0200
Committer: jvermillard <jv...@apache.org>
Committed: Wed Jun 19 10:13:39 2013 +0200
----------------------------------------------------------------------
.../org/apache/mina/util/ByteBufferDumper.java | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina/blob/ff21d87f/core/src/main/java/org/apache/mina/util/ByteBufferDumper.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mina/util/ByteBufferDumper.java b/core/src/main/java/org/apache/mina/util/ByteBufferDumper.java
index 359e08e..851abad 100644
--- a/core/src/main/java/org/apache/mina/util/ByteBufferDumper.java
+++ b/core/src/main/java/org/apache/mina/util/ByteBufferDumper.java
@@ -40,23 +40,24 @@ public class ByteBufferDumper {
* @return A dump of this ByteBuffer
*/
public static String dump(ByteBuffer buffer, int nbBytes, boolean toAscii) {
- byte[] data = buffer.array();
int start = buffer.position();
int size = Math.min(buffer.remaining(), nbBytes >= 0 ? nbBytes : Integer.MAX_VALUE);
int length = buffer.remaining();
+ ByteBuffer slice = buffer.slice();
// is not ASCII printable ?
boolean binaryContent = false;
if (toAscii) {
- for (int i = start; i < size; i++) {
- byte b = data[i];
+ while (slice.hasRemaining()) {
+ byte b = slice.get();
if (((b < 32) || (b > 126)) && (b != 13) && (b != 10)) {
binaryContent = true;
break;
}
}
+ slice.flip();
}
if (!toAscii || binaryContent) {
@@ -64,18 +65,18 @@ public class ByteBufferDumper {
out.append("ByteBuffer[len=").append(length).append(",bytes='");
// fill the first
- int byteValue = data[start] & 0xFF;
+ int byteValue = slice.get(0) & 0xFF;
boolean isFirst = true;
// and the others, too
- for (int i = start; i < size; i++) {
+ while (slice.hasRemaining()) {
if (isFirst) {
isFirst = false;
} else {
out.append(' ');
}
- byteValue = data[i] & 0xFF;
+ byteValue = slice.get() & 0xFF;
out.append(new String(new byte[] { '0', 'x', HEX_CHAR[(byteValue & 0x00F0) >> 4],
HEX_CHAR[byteValue & 0x000F] }));
}
@@ -86,8 +87,10 @@ public class ByteBufferDumper {
} else {
StringBuilder sb = new StringBuilder(size);
- sb.append("ByteBuffer[len=").append(length).append(",str='").append(new String(data, start, size))
- .append("']");
+ byte array[] = new byte[slice.remaining()];
+ buffer.get(array);
+
+ sb.append("ByteBuffer[len=").append(length).append(",str='").append(new String(array)).append("']");
return sb.toString();
}