Skip to content
Permalink
Browse files

[JENKINS-8856] Nicer logging of ASCII text.

It's no longer a 'hex' dump, but much more readable for all known error cases (JVM dying and writing to standard out).
  • Loading branch information
daniel-beck committed Jul 26, 2013
1 parent d0334ba commit aae9b457c15f88b7a8607978177f1673db2ec2ff
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}));
}
}

1 comment on commit aae9b45

@buildhive

This comment has been minimized.

Copy link

@buildhive buildhive commented on aae9b45 Aug 9, 2013

Jenkins » remoting #112 UNSTABLE
Looks like this commit caused a build failure
(what's this?)

Please sign in to comment.