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

View File

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