private static @Nullable Charset guessCharsetFromContent(byte @NotNull [] content) {
    if (content.length == 0) return null;
    // can't use CharsetToolkit.guessEncoding here because of false-positive INVALID_UTF8
    CharsetToolkit toolkit = new CharsetToolkit(content, Charset.defaultCharset(), false);

    Charset fromBOM = toolkit.guessFromBOM();
    if (fromBOM != null) return fromBOM;

    CharsetToolkit.GuessedEncoding guessedEncoding = toolkit.guessFromContent(content.length);
    return switch (guessedEncoding) {
      case SEVEN_BIT -> StandardCharsets.US_ASCII;
      case VALID_UTF8 -> StandardCharsets.UTF_8;
      default -> null;
    };
  }
private static @Nullable Charset guessCharsetFromContent(byte @NotNull [] content)