当前位置: 首页>>代码示例>>Java>>正文


Java LoadTextUtil.getTextByBinaryPresentation方法代码示例

本文整理汇总了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;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:EncodingUtil.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:FileContentImpl.java

示例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;
  }
}
 
开发者ID:consulo,项目名称:consulo,代码行数:18,代码来源:EncodingUtil.java

示例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;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:19,代码来源:FileContentImpl.java

示例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));
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:LoadTextUtilTest.java

示例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);
    }
  };
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:ApplyTextFilePatch.java

示例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 "";
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:16,代码来源:CacheUtil.java

示例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));
  }
}
 
开发者ID:consulo,项目名称:consulo,代码行数:9,代码来源:LoadTextUtilTest.java

示例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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:6,代码来源:PatchVirtualFileReader.java


注:本文中的com.intellij.openapi.fileEditor.impl.LoadTextUtil.getTextByBinaryPresentation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。