Permalink
Browse files

Merge pull request #16 from daniel-beck/master

More readable diagnostic for JENKINS-8856
  • Loading branch information...
jglick committed Aug 9, 2013
2 parents a567306 + 2a6c74d commit 8b509574e538061ecce717510688bb18acfc3be3
Showing with 25 additions and 4 deletions.
  1. +20 −4 src/main/java/hudson/remoting/HexDump.java
  2. +5 −0 src/test/java/hudson/remoting/HexDumpTest.java
@@ -11,19 +11,35 @@ public static String toHex(byte[] buf) {
}
public static String toHex(byte[] buf, int start, int len) {
StringBuilder r = new StringBuilder(len*2);
boolean inText = false;
for (int i=0; i<len; i++) {
if (i > 0) {
r.append(' ');
}
byte b = buf[start+i];
if (b >= 0x20 && b <= 0x7e) {
r.append('\'').append((char) b).append('\'');
if (!inText) {
inText = true;
r.append('\'');
}
r.append((char) b);
} else {
if (inText) {
r.append("' ");
inText = false;
}
r.append("0x");
r.append(CODE.charAt((b>>4)&15));
r.append(CODE.charAt(b&15));
if (i < len - 1) {
if (b == 10) {
r.append('\n');
} else {
r.append(' ');
}
}
}
}
if (inText) {
r.append('\'');
}
return r.toString();
}
}
@@ -8,5 +8,10 @@
public class HexDumpTest extends TestCase {
public void test1() {
assertEquals("0x00 0x01 0xff 'A'", HexDump.toHex(new byte[] {0, 1, -1, 65}));
assertEquals("0x00 0x01 0xff 'ABC'", HexDump.toHex(new byte[] {0, 1, -1, 65, 66, 67}));
assertEquals("'AAAA' 0x00", HexDump.toHex(new byte[] {65, 65, 65, 65, 0}));
}
public void testMultiline() {
assertEquals("'A A' 0x0a\n' AA'", HexDump.toHex(new byte[] {65, 32, 65, 10, 32, 65, 65}));
}
}

0 comments on commit 8b50957

Please sign in to comment.