Magic8 (@NotNull VirtualFile virtualFile, @NotNull CharSequence text, byte @NotNull [] bytesOnDisk, @NotNull Charset charset) { try { String lineSeparator = FileDocumentManager.getInstance().getLineSeparator(virtualFile, null); CharSequence textToSave = lineSeparator.equals("\n") ? text : StringUtilRt.convertLineSeparators(text, lineSeparator); Pair<Charset, byte[]> chosen = LoadTextUtil.chooseMostlyHarmlessCharset(virtualFile.getCharset(), charset, textToSave.toString()); byte[] saved = chosen.second; CharSequence textLoadedBack = LoadTextUtil.getTextByBinaryPresentation(saved, charset); return !StringUtil.equals(text, textLoadedBack) ? Magic8.NO_WAY : Arrays.equals(saved, bytesOnDisk) ? Magic8.ABSOLUTELY : Magic8.WELL_IF_YOU_INSIST; } catch (UnsupportedOperationException e) { // unsupported encoding return Magic8.NO_WAY; } }