MCPcopy Create free account
hub / github.com/OpenTSDB/asynchbase / pretty

Method pretty

src/Bytes.java:335–366  ·  view source on GitHub ↗

Pretty-prints a byte array into a human-readable output buffer. @param outbuf The buffer where to write the output. @param array The (possibly null) array to pretty-print.

(final StringBuilder outbuf, final byte[] array)

Source from the content-addressed store, hash-verified

333 * @param array The (possibly {@code null}) array to pretty-print.
334 */
335 public static void pretty(final StringBuilder outbuf, final byte[] array) {
336 if (array == null) {
337 outbuf.append("null");
338 return;
339 }
340 int ascii = 0;
341 final int start_length = outbuf.length();
342 final int n = array.length;
343 outbuf.ensureCapacity(start_length + 1 + n + 1);
344 outbuf.append('"');
345 for (int i = 0; i < n; i++) {
346 final byte b = array[i];
347 if (' ' <= b && b <= '~') {
348 ascii++;
349 outbuf.append((char) b);
350 } else if (b == '\n') {
351 outbuf.append('\\').append('n');
352 } else if (b == '\t') {
353 outbuf.append('\\').append('t');
354 } else {
355 outbuf.append("\\x")
356 .append((char) HEX[(b >>> 4) & 0x0F])
357 .append((char) HEX[b & 0x0F]);
358 }
359 }
360 if (ascii < n / 2) {
361 outbuf.setLength(start_length);
362 outbuf.append(Arrays.toString(array));
363 } else {
364 outbuf.append('"');
365 }
366 }
367
368 /**
369 * Pretty-prints an array of byte arrays into a human-readable output buffer.

Callers 15

assertGreaterMethod · 0.95
toStringMethod · 0.95
toStringMethod · 0.95
toStringMethod · 0.95
toStringMethod · 0.95
toStringWithQualifierMethod · 0.95
checkArrayLengthMethod · 0.95
readProtobufMethod · 0.95

Calls 3

appendMethod · 0.80
toStringMethod · 0.45
getMethod · 0.45

Tested by 1

assertGreaterMethod · 0.76