private static @NotNull DetectResult detectHardCharset(@NotNull VirtualFile virtualFile,
                                                byte @NotNull [] internalBuffer,
                                                int length,
                                                @NotNull FileType fileType) {
    String charsetName = fileType.getCharset(virtualFile, internalBuffer); // todo[cdr]
    Charset charset = charsetName == null ? null : CharsetToolkit.forName(charsetName);
    DetectResult detectResult = guessFromContent(virtualFile, internalBuffer, length);
    Charset hardCodedCharset = charset == null ? detectResult.hardCodedCharset : charset;
    CharsetToolkit.GuessedEncoding guessed = detectResult.guessed;
    byte[] detectedBOM = detectResult.BOM;
    Charset result;
    if (hardCodedCharset == null && guessed == CharsetToolkit.GuessedEncoding.VALID_UTF8) {
      result = StandardCharsets.UTF_8;
    }
    else {
      result = hardCodedCharset;
    }
    return new DetectResult(result, guessed, detectedBOM);
  }
private static @NotNull DetectResult detectHardCharset(@NotNull VirtualFile virtualFile,
                                                byte @NotNull [] internalBuffer,
                                                int length,
                                                @NotNull FileType fileType)