@Test public void testLoggable() throws Exception { String hexRegex = "^\\\\x[0-9a-f][0-9a-f]$"; for (int i = Byte.MIN_VALUE; i < (byte)' '; i++) { String l = ByteArrayUtil2.loggable(new byte[]{(byte)i}); assertTrue(l.matches(hexRegex), l + " matches /" + hexRegex + "/"); } for (int i = (byte)' '; i < (byte)'"'; i++) { assertEquals(Character.toString((char) i), ByteArrayUtil2.loggable(new byte[]{(byte)i})); } assertEquals("\\x22", ByteArrayUtil2.loggable(new byte[]{(byte)'"'})); for (int i = (byte)'"' + 1; i < (byte)'='; i++) { assertEquals(Character.toString((char) i), ByteArrayUtil2.loggable(new byte[]{(byte)i})); } assertEquals("\\x3d", ByteArrayUtil2.loggable(new byte[]{(byte)'='})); for (int i = (byte)'=' + 1; i < (byte)'\\'; i++) { assertEquals(Character.toString((char) i), ByteArrayUtil2.loggable(new byte[]{(byte)i})); } assertEquals("\\\\", ByteArrayUtil2.loggable(new byte[]{'\\'})); for (int i = (byte)'\\' + 1; i < (byte)127; i++) { assertEquals(Character.toString((char) i), ByteArrayUtil2.loggable(new byte[]{(byte)i})); } assertEquals("\\x7f", ByteArrayUtil2.loggable(new byte[]{127})); }
@API(API.Status.MAINTAINED) @Nullable public static String loggable(@Nullable byte[] bytes) { if (bytes == null) { return null; } else { StringBuilder sb = new StringBuilder(); for (byte b : bytes) { if (b >= MINIMUM_PRINTABLE_CHARACTER && b < MAXIMUM_PRINTABLE_CHARACTER && b != BACKSLASH_CHARACTER && b != EQUALS_CHARACTER && b != DOUBLE_QUOTE_CHARACTER) { sb.append((char)b); } else if (b == BACKSLASH_CHARACTER) { sb.append("\\\\"); } else { sb.append(String.format("\\x%02x", b)); } } return sb.toString(); } }
ByteArrayUtil2 { @API(API.Status.MAINTAINED) @Nullable public static String loggable(@Nullable byte[] bytes) { if (bytes == null) { return null; } else { StringBuilder sb = new StringBuilder(); for (byte b : bytes) { if (b >= MINIMUM_PRINTABLE_CHARACTER && b < MAXIMUM_PRINTABLE_CHARACTER && b != BACKSLASH_CHARACTER && b != EQUALS_CHARACTER && b != DOUBLE_QUOTE_CHARACTER) { sb.append((char)b); } else if (b == BACKSLASH_CHARACTER) { sb.append("\\\\"); } else { sb.append(String.format("\\x%02x", b)); } } return sb.toString(); } } }
ByteArrayUtil2 { @API(API.Status.MAINTAINED) @Nullable public static String loggable(@Nullable byte[] bytes) { if (bytes == null) { return null; } else { StringBuilder sb = new StringBuilder(); for (byte b : bytes) { if (b >= MINIMUM_PRINTABLE_CHARACTER && b < MAXIMUM_PRINTABLE_CHARACTER && b != BACKSLASH_CHARACTER && b != EQUALS_CHARACTER && b != DOUBLE_QUOTE_CHARACTER) { sb.append((char)b); } else if (b == BACKSLASH_CHARACTER) { sb.append("\\\\"); } else { sb.append(String.format("\\x%02x", b)); } } return sb.toString(); } } private  ByteArrayUtil2(); }
ByteArrayUtil2 { @API(API.Status.MAINTAINED) @Nullable public static String loggable(@Nullable byte[] bytes) { if (bytes == null) { return null; } else { StringBuilder sb = new StringBuilder(); for (byte b : bytes) { if (b >= MINIMUM_PRINTABLE_CHARACTER && b < MAXIMUM_PRINTABLE_CHARACTER && b != BACKSLASH_CHARACTER && b != EQUALS_CHARACTER && b != DOUBLE_QUOTE_CHARACTER) { sb.append((char)b); } else if (b == BACKSLASH_CHARACTER) { sb.append("\\\\"); } else { sb.append(String.format("\\x%02x", b)); } } return sb.toString(); } } private  ByteArrayUtil2(); @Nullable static String toHexString(@Nullable byte[] bytes); @API(API.Status.MAINTAINED) @Nullable static String loggable(@Nullable byte[] bytes); @API(API.Status.MAINTAINED) @Nullable static byte[] unprint(@Nullable String loggedBytes); static boolean hasCommonPrefix(@Nonnull byte[] bytes1, @Nonnull byte[] bytes2, int prefixSize); }
ByteArrayUtil2 { @API(API.Status.MAINTAINED) @Nullable public static String loggable(@Nullable byte[] bytes) { if (bytes == null) { return null; } else { StringBuilder sb = new StringBuilder(); for (byte b : bytes) { if (b >= MINIMUM_PRINTABLE_CHARACTER && b < MAXIMUM_PRINTABLE_CHARACTER && b != BACKSLASH_CHARACTER && b != EQUALS_CHARACTER && b != DOUBLE_QUOTE_CHARACTER) { sb.append((char)b); } else if (b == BACKSLASH_CHARACTER) { sb.append("\\\\"); } else { sb.append(String.format("\\x%02x", b)); } } return sb.toString(); } } private  ByteArrayUtil2(); @Nullable static String toHexString(@Nullable byte[] bytes); @API(API.Status.MAINTAINED) @Nullable static String loggable(@Nullable byte[] bytes); @API(API.Status.MAINTAINED) @Nullable static byte[] unprint(@Nullable String loggedBytes); static boolean hasCommonPrefix(@Nonnull byte[] bytes1, @Nonnull byte[] bytes2, int prefixSize);  }