BytesMapLogParam implements LogParam { @Override public void append(StringBuilder builder, Set<String> maskedFields, int maxParamLength) { int maxLength = builder.length() + maxParamLength; builder.append('{'); int index = 0; for (Map.Entry<String, byte[]> entry : values.entrySet()) { if (index > 0) builder.append(", "); builder.append(entry.getKey()) .append('=') .append(new String(entry.getValue(), UTF_8)); if (builder.length() >= maxLength) { builder.setLength(maxLength); builder.append("...(truncated)"); return; } index++; } builder.append('}'); } BytesMapLogParam(Map<String, byte[]> values); @Override void append(StringBuilder builder, Set<String> maskedFields, int maxParamLength);  }
@Test void append() { var param = new BytesMapLogParam(Map.of("k1", bytes("v1"), "k2", bytes("v2"))); var builder = new StringBuilder(); param.append(builder, Set.of(), 1000); assertThat(builder.toString()) .contains("k1=v1") .contains("k2=v2"); }
@Test void appendWithTruncation() { Map<String, byte[]> values = new LinkedHashMap<>(); values.put("k1", bytes("v1")); values.put("k2", bytes("v2")); var param = new BytesMapLogParam(values); var builder = new StringBuilder(); param.append(builder, Set.of(), 5); assertThat(builder.toString()) .isEqualTo("{k1=v...(truncated)"); }