private static @NotNull Charset takeCharsetOrGuessUTF(@NotNull Charset charset, byte @NotNull [] content) {
    if (StandardCharsets.UTF_8.equals(charset)) {
      // GuessedEncoding can't detect UTF8-incompatible charsets, verification can be skipped
      return charset;
    }

    if (CharsetToolkit.tryDecodeString(content, charset) != null) {
      // charset is OK
      return charset;
    }

    Charset charsetFromContent = guessCharsetFromContent(content);
    if (charsetFromContent != null) {
      return charsetFromContent;
    }

    // charset is NOT OK, but we don't know better
    return charset;
  }
private static @NotNull Charset takeCharsetOrGuessUTF(@NotNull Charset charset, byte @NotNull [] content)