@NotNull
 private static Pair.NonNull<Charset, byte[]> doDetectCharsetAndSetBOM(
     @NotNull VirtualFile virtualFile,
     @NotNull byte[] content,
     boolean saveBOM,
     @NotNull FileType fileType) {
   @NotNull
   Charset charset =
       virtualFile.isCharsetSet()
           ? virtualFile.getCharset()
           : detectCharset(virtualFile, content, fileType);
   Pair.NonNull<Charset, byte[]> bomAndCharset = getCharsetAndBOM(content, charset);
   final byte[] bom = bomAndCharset.second;
   if (saveBOM && bom.length != 0) {
     virtualFile.setBOM(bom);
     setCharsetWasDetectedFromBytes(virtualFile, AUTO_DETECTED_FROM_BOM);
   }
   return bomAndCharset;
 }