Added option to add header to 'printArray'. Printed data is now in a single sys.err call

This commit is contained in:
nathan 2016-03-10 23:12:59 +01:00
parent 77492816e2
commit b3d4dc431c
1 changed files with 22 additions and 10 deletions

View File

@ -736,24 +736,36 @@ class Sys {
public static
void printArray(byte[] bytes, int length, boolean includeByteCount) {
printArray(bytes, length, includeByteCount, 40);
printArray(bytes, length, includeByteCount, 40, null);
}
public static
void printArray(byte[] bytes, int length, boolean includeByteCount, int lineLength) {
if (includeByteCount) {
System.err.println("Bytes: " + length);
}
void printArray(byte[] bytes, int length, boolean includeByteCount, int lineLength, String header) {
int comma = length - 1;
StringBuilder builder;
int builderLength = length + comma + 2;
if (includeByteCount) {
builderLength += 7 + Integer.toString(length)
.length();
}
if (lineLength > 0) {
builder = new StringBuilder(length + comma + length / lineLength + 2);
builderLength += length / lineLength;
}
else {
builder = new StringBuilder(length + comma + 2);
if (header != null) {
builderLength += header.length() + 2;
}
StringBuilder builder = new StringBuilder(builderLength);
if (header != null) {
builder.append(header)
.append(OS.LINE_SEPARATOR);
}
if (includeByteCount) {
builder.append("Bytes: ").append(length).append(OS.LINE_SEPARATOR);
}
builder.append("{");
for (int i = 0; i < length; i++) {