ByteBufHttpData implements HttpData, ResourceLeakHint { @Override public String toString(Charset charset) { requireNonNull(charset, "charset"); if (array != null) { return new String(array, charset); } else { return buf.toString(charset); } } ByteBufHttpData(ByteBuf buf, boolean pooled); private  ByteBufHttpData(ByteBuf buf, int flags, @Nullable byte[] array); @Override byte[] array(); @Override int length(); @Override String toString(Charset charset); @Override String toString(); @Override String toHintString(); @Override InputStream toInputStream(); @Override boolean isEndOfStream(); @Override ByteBufHttpData withEndOfStream(boolean endOfStream); @Override boolean isPooled(); @Override ByteBuf byteBuf(ByteBufAccessMode mode); @Override ByteBuf byteBuf(int offset, int length, ByteBufAccessMode mode); @Override void touch(@Nullable Object hint); @Override void close(); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test void testToString() { assertThat(new ByteBufHttpData(Unpooled.copiedBuffer("foo", StandardCharsets.US_ASCII), false)) .hasToString("{3B, text=foo}"); assertThat(new ByteBufHttpData(Unpooled.copiedBuffer("\u0001\u0002", StandardCharsets.US_ASCII), false)) .hasToString("{2B, hex=0102}"); assertThat(new ByteBufHttpData(Unpooled.copiedBuffer("foo", StandardCharsets.US_ASCII), false) .withEndOfStream()).hasToString("{3B, EOS, text=foo}"); assertThat(new ByteBufHttpData(Unpooled.copiedBuffer("\u0001\u0002", StandardCharsets.US_ASCII), false) .withEndOfStream()).hasToString("{2B, EOS, hex=0102}"); assertThat(new ByteBufHttpData(Unpooled.copiedBuffer("foo", StandardCharsets.US_ASCII), true)) .hasToString("{3B, pooled, text=foo}"); assertThat(new ByteBufHttpData(Unpooled.copiedBuffer("\u0001\u0002", StandardCharsets.US_ASCII), true)) .hasToString("{2B, pooled, hex=0102}"); final ByteBufHttpData data1 = new ByteBufHttpData(Unpooled.copiedBuffer("bar", StandardCharsets.US_ASCII), true); data1.close(); assertThat(data1).hasToString("{3B, pooled, closed}"); final ByteBufHttpData data2 = new ByteBufHttpData(Unpooled.unreleasableBuffer( Unpooled.copiedBuffer("bar", StandardCharsets.US_ASCII)), true); data2.close(); assertThat(data2).hasToString("{3B, pooled, closed, text=bar}"); assertThat(new ByteBufHttpData(Unpooled.copiedBuffer("0123456789abcdef\u0001", StandardCharsets.US_ASCII), false)) .hasToString("{17B, text=0123456789abcdef}"); }