本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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());
}
示例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());
}
示例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());
}
示例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;
}
示例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;
}