本文整理汇总了Java中com.intellij.openapi.fileEditor.impl.LoadTextUtil.getTextByBinaryPresentation方法的典型用法代码示例。如果您正苦于以下问题:Java LoadTextUtil.getTextByBinaryPresentation方法的具体用法?Java LoadTextUtil.getTextByBinaryPresentation怎么用?Java LoadTextUtil.getTextByBinaryPresentation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.fileEditor.impl.LoadTextUtil
的用法示例。
在下文中一共展示了LoadTextUtil.getTextByBinaryPresentation方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isSafeToConvertTo
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
static Magic8 isSafeToConvertTo(@NotNull VirtualFile virtualFile, @NotNull String text, @NotNull byte[] bytesOnDisk, @NotNull Charset charset) {
try {
String lineSeparator = FileDocumentManager.getInstance().getLineSeparator(virtualFile, null);
String textToSave = lineSeparator.equals("\n") ? text : StringUtil.convertLineSeparators(text, lineSeparator);
Pair<Charset, byte[]> chosen = LoadTextUtil.chooseMostlyHarmlessCharset(virtualFile.getCharset(), charset, textToSave);
byte[] saved = chosen.second;
CharSequence textLoadedBack = LoadTextUtil.getTextByBinaryPresentation(saved, charset);
return !text.equals(textLoadedBack.toString()) ? Magic8.NO_WAY : Arrays.equals(saved, bytesOnDisk) ? Magic8.ABSOLUTELY : Magic8.WELL_IF_YOU_INSIST;
}
catch (UnsupportedOperationException e) { // unsupported encoding
return Magic8.NO_WAY;
}
}
示例2: getContentAsText
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
@NotNull
@Override
public CharSequence getContentAsText() {
if (myFileType.isBinary()) {
throw new IllegalDataException("Cannot obtain text for binary file type : " + myFileType.getDescription());
}
final CharSequence content = getUserData(IndexingDataKeys.FILE_TEXT_CONTENT_KEY);
if (content != null) {
return content;
}
if (myContentAsText == null) {
if (myContent != null) {
myContentAsText = LoadTextUtil.getTextByBinaryPresentation(myContent, myCharset);
myContent = null; // help gc, indices are expected to use bytes or chars but not both
}
}
return myContentAsText;
}
示例3: isSafeToConvertTo
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
static Magic8 isSafeToConvertTo(@Nonnull VirtualFile virtualFile, @Nonnull String text, @Nonnull byte[] bytesOnDisk, @Nonnull Charset charset) {
try {
String lineSeparator = FileDocumentManager.getInstance().getLineSeparator(virtualFile, null);
String textToSave = lineSeparator.equals("\n") ? text : StringUtil.convertLineSeparators(text, lineSeparator);
Pair<Charset, byte[]> chosen = LoadTextUtil.chooseMostlyHarmlessCharset(virtualFile.getCharset(), charset, textToSave);
byte[] saved = chosen.second;
CharSequence textLoadedBack = LoadTextUtil.getTextByBinaryPresentation(saved, charset);
return !text.equals(textLoadedBack.toString()) ? Magic8.NO_WAY : Arrays.equals(saved, bytesOnDisk) ? Magic8.ABSOLUTELY : Magic8.WELL_IF_YOU_INSIST;
}
catch (UnsupportedOperationException e) { // unsupported encoding
return Magic8.NO_WAY;
}
}
示例4: getContentAsText
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
@Nonnull
@Override
public CharSequence getContentAsText() {
if (myFileType.isBinary()) {
throw new IllegalDataException("Cannot obtain text for binary file type : " + myFileType.getDescription());
}
final CharSequence content = getUserData(IndexingDataKeys.FILE_TEXT_CONTENT_KEY);
if (content != null) {
return content;
}
if (myContentAsText == null) {
if (myContent != null) {
myContentAsText = LoadTextUtil.getTextByBinaryPresentation(myContent, myCharset);
myContent = null; // help gc, indices are expected to use bytes or chars but not both
}
}
return myContentAsText;
}
示例5: doTest
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
private static void doTest(String source, String expected, String expectedSeparator) {
final LightVirtualFile vFile = new LightVirtualFile("test.txt");
final CharSequence real = LoadTextUtil.getTextByBinaryPresentation(source.getBytes(), vFile);
assertTrue("content", Comparing.equal(expected, real));
if (expectedSeparator != null) {
assertEquals("detected line separator", expectedSeparator, FileDocumentManager.getInstance().getLineSeparator(vFile, null));
}
}
示例6: applyChange
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
@Nullable
protected Result applyChange(final Project project, final VirtualFile fileToPatch, final FilePath pathBeforeRename, final Getter<CharSequence> baseContents) throws IOException {
byte[] fileContents = fileToPatch.contentsToByteArray();
CharSequence text = LoadTextUtil.getTextByBinaryPresentation(fileContents, fileToPatch);
final GenericPatchApplier applier = new GenericPatchApplier(text, myPatch.getHunks());
if (applier.execute()) {
final Document document = FileDocumentManager.getInstance().getDocument(fileToPatch);
if (document == null) {
throw new IOException("Failed to set contents for updated file " + fileToPatch.getPath());
}
document.setText(applier.getAfter());
FileDocumentManager.getInstance().saveDocument(document);
return new Result(applier.getStatus()) {
@Override
public ApplyPatchForBaseRevisionTexts getMergeData() {
return null;
}
};
}
applier.trySolveSomehow();
return new Result(ApplyPatchStatus.FAILURE) {
@Override
public ApplyPatchForBaseRevisionTexts getMergeData() {
return ApplyPatchForBaseRevisionTexts.create(project, fileToPatch, pathBeforeRename, myPatch, baseContents);
}
};
}
示例7: getContentText
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
public static CharSequence getContentText(final FileContent content) {
final Document doc = FileDocumentManager.getInstance().getCachedDocument(content.getVirtualFile());
if (doc != null) return doc.getCharsSequence();
CharSequence cached = content.getUserData(CONTENT_KEY);
if (cached != null) return cached;
try {
cached = LoadTextUtil.getTextByBinaryPresentation(content.getBytes(), content.getVirtualFile(), false, false);
cached = content.putUserDataIfAbsent(CONTENT_KEY, cached);
return cached;
}
catch (IOException e) {
return "";
}
}
示例8: doTest
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
private static void doTest(String source, String expected, String expectedSeparator) {
final LightVirtualFile vFile = new LightVirtualFile("test.txt");
final CharSequence real = LoadTextUtil.getTextByBinaryPresentation(source.getBytes(CharsetToolkit.US_ASCII_CHARSET), vFile);
assertTrue("content", Comparing.equal(expected, real));
if (expectedSeparator != null) {
assertEquals("detected line separator", expectedSeparator, FileDocumentManager.getInstance().getLineSeparator(vFile, null));
}
}
示例9: create
import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
public static PatchReader create(final VirtualFile virtualFile) throws IOException {
final byte[] patchContents = virtualFile.contentsToByteArray();
final CharSequence patchText = LoadTextUtil.getTextByBinaryPresentation(patchContents, virtualFile);
return new PatchReader(patchText);
}