public static String readAllBytes(InputStream input, Charset charset) throws IOException {
    if (charset == null) {
      input = ensureMarkSupport(input);
      input.mark(4);
      byte[] buffer = new byte[4];
      int bytesRead = fillBuffer(input, buffer);
      input.reset();

      charset = detectUtfCharset0(buffer, bytesRead);

      if (charset == null) {
        throw new IOException("Unsupported UCS-4 variant (neither UTF-32BE nor UTF32-LE)");
      }
    }
    Reader reader = new InputStreamReader(input, charset);
    return readAllChars(reader);
  }
@Test
  void validateSupportForUnmarkableStreams() throws IOException {
    assertEquals("ABCD",
        UtfTextUtils.readAllBytes(new UnmarkableInputStream(new ByteArrayInputStream(hexBytes("41424344"))), null));
  }