Skip to content

Commit

Permalink
Improved dump of byte[]
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Oct 14, 2015
1 parent edb0d4f commit a885a2d
Showing 1 changed file with 13 additions and 2 deletions.
Expand Up @@ -40,6 +40,8 @@
*/
public class PrettyPrinter {

private static final int BYTE_ARRAY_MAX_LEN = 64;

private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyy-mm-dd hh:mm:ss");

private static String defaultNamespacePrefix = null;
Expand Down Expand Up @@ -229,12 +231,21 @@ public static String prettyPrint(Object[] value) {
public static String prettyPrint(byte[] value) {
StringBuilder sb = new StringBuilder();
sb.append("byte[");
for(int i=0; i<value.length; i++) {
int printlen = value.length;
if (printlen > BYTE_ARRAY_MAX_LEN) {
printlen = BYTE_ARRAY_MAX_LEN;
}
for(int i=0; i < printlen; i++) {
sb.append(Byte.toString(value[i]));
if (i<value.length-1) {
if (i < printlen) {
sb.append(',');
}
}
if (value.length > BYTE_ARRAY_MAX_LEN) {
sb.append(",... ");
sb.append(value.length);
sb.append(" bytes total");
}
sb.append("]");
return sb.toString();
}
Expand Down

0 comments on commit a885a2d

Please sign in to comment.