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


Java CharsetToolkit.bytesToString方法代码示例

本文整理汇总了Java中com.intellij.openapi.vfs.CharsetToolkit.bytesToString方法的典型用法代码示例。如果您正苦于以下问题:Java CharsetToolkit.bytesToString方法的具体用法?Java CharsetToolkit.bytesToString怎么用?Java CharsetToolkit.bytesToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.openapi.vfs.CharsetToolkit的用法示例。


在下文中一共展示了CharsetToolkit.bytesToString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDocument

import com.intellij.openapi.vfs.CharsetToolkit; //导入方法依赖的package包/类
@Override
@Nullable
public Document getDocument() {
  if (myDocument == null) {
    if (isBinary()) return null;

    String text = null;
    try {
      Charset charset = ObjectUtils.notNull(myCharset, EncodingProjectManager.getInstance(myProject).getDefaultCharset());
      text = CharsetToolkit.bytesToString(myBytes, charset);
    }
    catch (IllegalCharsetNameException ignored) { }

    //  Still NULL? only if not supported or an exception was thrown.
    //  Decode a string using the truly default encoding.
    if (text == null) text = new String(myBytes);
    text = LineTokenizer.correctLineSeparators(text);

    myDocument = EditorFactory.getInstance().createDocument(text);
    myDocument.setReadOnly(true);
  }

  return myDocument;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:BinaryContent.java

示例2: getContent

import com.intellij.openapi.vfs.CharsetToolkit; //导入方法依赖的package包/类
@Nullable
public String getContent() throws VcsException {
  if (myContents == null) {
    BufferExposingByteArrayOutputStream bos = new BufferExposingByteArrayOutputStream(2048);
    try {
      myRepository.getFile(myPath, -1, null, bos);
      myRepository.closeSession();
    } catch (SVNException e) {
      throw new VcsException(e);
    }
    final byte[] bytes = bos.toByteArray();
    final Charset charset = myFilePath.getCharset();
    myContents = CharsetToolkit.bytesToString(bytes, charset);
  }
  return myContents;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:DiffContentRevision.java

示例3: getOrLoadAsString

import com.intellij.openapi.vfs.CharsetToolkit; //导入方法依赖的package包/类
@Nullable
public static String getOrLoadAsString(Project project,
                                       FilePath file,
                                       VcsRevisionNumber number,
                                       VcsKey key,
                                       UniqueType type,
                                       Throwable2Computable<byte[], VcsException, IOException> loader, @Nullable Charset charset)
  throws VcsException, IOException {
  if (charset == null) {
    return getOrLoadAsString(project, file, number, key, type, loader);
  }
  final byte[] bytes = getOrLoadAsBytes(project, file, number, key, type, loader);
  return CharsetToolkit.bytesToString(bytes, charset);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:ContentRevisionCache.java

示例4: bytesToString

import com.intellij.openapi.vfs.CharsetToolkit; //导入方法依赖的package包/类
private static String bytesToString(FilePath path, @NotNull byte[] bytes) {
  Charset charset = null;
  if (path.getVirtualFile() != null) {
    charset = path.getVirtualFile().getCharset();
  }

  if (charset != null) {
    int bomLength = CharsetToolkit.getBOMLength(bytes, charset);
    final CharBuffer charBuffer = charset.decode(ByteBuffer.wrap(bytes, bomLength, bytes.length - bomLength));
    return charBuffer.toString();
  }

  return CharsetToolkit.bytesToString(bytes, EncodingRegistry.getInstance().getDefaultCharset());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:ContentRevisionCache.java

示例5: loadRevisionContentGuessEncoding

import com.intellij.openapi.vfs.CharsetToolkit; //导入方法依赖的package包/类
public static String loadRevisionContentGuessEncoding(@NotNull final VcsFileRevision revision, @Nullable final VirtualFile file,
                                                      @Nullable final Project project) throws VcsException, IOException {
  final byte[] bytes = loadRevisionContent(revision);
  if (file != null) {
    return new String(bytes, file.getCharset());
  }
  EncodingManager e = project != null ? EncodingProjectManager.getInstance(project) : null;
  if (e == null) {
    e = EncodingManager.getInstance();
  }

  return CharsetToolkit.bytesToString(bytes, e.getDefaultCharset());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:VcsHistoryUtil.java

示例6: getContent

import com.intellij.openapi.vfs.CharsetToolkit; //导入方法依赖的package包/类
@Nullable
@Override
public String getContent() throws VcsException {
  if (myRevisionNumber.isWorkingVersion()) return VcsUtil.getFileContent(myHgFile.getFile().getPath());
  final HgFile fileToCat = HgUtil.getFileNameInTargetRevision(myProject, myRevisionNumber, myHgFile);
  return CharsetToolkit.bytesToString(HgUtil.loadContent(myProject, myRevisionNumber, fileToCat), getFile().getCharset());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:HgContentRevision.java

示例7: getContent

import com.intellij.openapi.vfs.CharsetToolkit; //导入方法依赖的package包/类
@Nullable
public String getContent() throws VcsException {
  if (myContent == null) {
    byte[] content = loadContent();
    if (content != null) {
      final Charset charset = myLocalFile.getCharset();
      myContent = CharsetToolkit.bytesToString(content, charset);
    }
  }
  return myContent;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:CvsContentRevision.java

示例8: getContent

import com.intellij.openapi.vfs.CharsetToolkit; //导入方法依赖的package包/类
@Override
@Nullable
public String getContent() throws VcsException {
  if (myContent == null) {
    try {
      final byte[] fileBytes = getUpToDateBinaryContent();
      myContent = fileBytes == null ? null : CharsetToolkit.bytesToString(fileBytes, myPath.getCharset());
    }
    catch (CannotFindCvsRootException e) {
      myContent = null;
    }
  }
  return myContent;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:CvsChangeProvider.java


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