public String toString() {
        return new String(buffer, 0, count, ConfigConstants.DEFAULT_CHARSET);
    }
@Test
    void testToString() throws IOException {
        byte[] data = "1234567890".getBytes(ConfigConstants.DEFAULT_CHARSET);

        try (ByteArrayOutputStreamWithPos stream = new ByteArrayOutputStreamWithPos(data.length)) {

            stream.write(data);
            assertThat(stream.toString().getBytes(ConfigConstants.DEFAULT_CHARSET))
                    .containsExactly(data);

            for (int i = 0; i < data.length; i++) {
                stream.setPosition(i);
                assertThat(stream.toString().getBytes(ConfigConstants.DEFAULT_CHARSET))
                        .containsExactly(Arrays.copyOf(data, i));
            }

            // validate that the stored bytes are still tracked properly even when expanding array
            stream.setPosition(data.length + 1);
            assertThat(stream.toString().getBytes(ConfigConstants.DEFAULT_CHARSET))
                    .containsExactly(Arrays.copyOf(data, data.length + 1));
        }
    }