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


Java CharsetToolkit类代码示例

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


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

示例1: getCourse

import com.intellij.openapi.vfs.CharsetToolkit; //导入依赖的package包/类
@Nullable
public static Course getCourse(String zipFilePath) {
  try {
    final JBZipFile zipFile = new JBZipFile(zipFilePath);
    final JBZipEntry entry = zipFile.getEntry(EduNames.COURSE_META_FILE);
    if (entry == null) {
      return null;
    }
    byte[] bytes = entry.getData();
    final String jsonText = new String(bytes, CharsetToolkit.UTF8_CHARSET);
    Gson gson = new GsonBuilder()
      .registerTypeAdapter(Task.class, new StudySerializationUtils.Json.TaskAdapter())
      .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
      .create();
    return gson.fromJson(jsonText, Course.class);
  }
  catch (IOException e) {
    LOG.error("Failed to unzip course archive");
    LOG.error(e);
  }
  return null;
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:23,代码来源:StudyProjectGenerator.java

示例2: createArchive

import com.intellij.openapi.vfs.CharsetToolkit; //导入依赖的package包/类
private String createArchive(String relativeArchivePath, String fileNameInArchive, String text) {
  try {
    File file = new File(getOrCreateProjectDir(), relativeArchivePath);
    ZipOutputStream output = new ZipOutputStream(new FileOutputStream(file));
    try {
      output.putNextEntry(new ZipEntry(fileNameInArchive));
      output.write(text.getBytes(CharsetToolkit.UTF8));
      output.closeEntry();
    }
    finally {
      output.close();
    }
    return FileUtil.toSystemIndependentName(file.getAbsolutePath());
  }
  catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:ArtifactBuilderOverwriteTest.java

示例3: testText

import com.intellij.openapi.vfs.CharsetToolkit; //导入依赖的package包/类
public void testText() throws Exception {
  doTest("Text.txt");
  Charset ascii = CharsetToolkit.forName("US-ASCII");
  VirtualFile myVFile = myFile.getVirtualFile();
  FileDocumentManager.getInstance().saveAllDocuments();
  EncodingManager.getInstance().setEncoding(myVFile, ascii);
  UIUtil.dispatchAllInvocationEvents(); // wait for reload requests to bubble up
  assertEquals(ascii, myVFile.getCharset());
  int start = myEditor.getCaretModel().getOffset();
  type((char)0x445);
  type((char)0x438);
  int end = myEditor.getCaretModel().getOffset();

  Collection<HighlightInfo> infos = doHighlighting();
  HighlightInfo info = assertOneElement(infos);
  assertEquals("Unsupported characters for the charset 'US-ASCII'", info.getDescription());
  assertEquals(start, info.startOffset);
  assertEquals(end, info.endOffset);

  backspace();
  backspace();

  doDoTest(true, false);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:LossyEncodingTest.java

示例4: readEntry

import com.intellij.openapi.vfs.CharsetToolkit; //导入依赖的package包/类
@Nullable
String readEntry(@NotNull final String endsWith) {
  try {
    return processStream(new StreamProcessor<String>() {
      @Override
      public String consume(@NotNull ZipInputStream stream) throws IOException {
        ZipEntry entry;
        while ((entry = stream.getNextEntry()) != null) {
          if (entry.getName().endsWith(endsWith)) {
            return StreamUtil.readText(stream, CharsetToolkit.UTF8_CHARSET);
          }
        }
        return null;
      }
    });
  }
  catch (IOException ignored) {
    return null;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:LocalArchivedTemplate.java

示例5: readUsageFile

import com.intellij.openapi.vfs.CharsetToolkit; //导入依赖的package包/类
@Nullable
private static Pair<Date, File> readUsageFile(File usageFile) {
  try {
    final List<String> lines = FileUtil.loadLines(usageFile, CharsetToolkit.UTF8_CHARSET.name());
    if (!lines.isEmpty()) {
      final String dateString = lines.get(0);
      final Date date;
      synchronized (USAGE_STAMP_DATE_FORMAT) {
        date = USAGE_STAMP_DATE_FORMAT.parse(dateString);
      }
      final File projectFile = lines.size() > 1? new File(lines.get(1)) : null;
      return Pair.create(date, projectFile);
    }
  }
  catch (Throwable e) {
    LOG.info(e);
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:BuildManager.java

示例6: load

import com.intellij.openapi.vfs.CharsetToolkit; //导入依赖的package包/类
@Override
public void load(@NotNull Consumer<String> consumer) {
  try {
    BufferedReader br = new BufferedReader(new InputStreamReader(stream, CharsetToolkit.UTF8_CHARSET));
    try {
      String line;
      while ((line = br.readLine()) != null) {
        consumer.consume(line);
      }
    }
    finally {
      br.close();
    }
  }
  catch (Exception e) {
    Logger.getInstance(StreamLoader.class).error(e);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:StreamLoader.java

示例7: convertStreamToString

import com.intellij.openapi.vfs.CharsetToolkit; //导入依赖的package包/类
private static String convertStreamToString(InputStream is) {
  if (is != null) {
    StringBuilder sb = new StringBuilder();

    try {
      BufferedReader reader = new BufferedReader(new InputStreamReader(is, CharsetToolkit.UTF8_CHARSET));
      try {
        String line;
        while ((line = reader.readLine()) != null) {
          sb.append(line).append('\n');
        }
      }
      finally {
        reader.close();
      }
    }
    catch (Exception e) {
      throw new RuntimeException(e);
    }

    return sb.toString();
  }
  else {
    return "";
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:SplitterTest.java

示例8: 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

示例9: loadTemplate

import com.intellij.openapi.vfs.CharsetToolkit; //导入依赖的package包/类
@NotNull
public static String loadTemplate(@NotNull ClassLoader loader, @NotNull String templateName, @Nullable Map<String, String> variables) throws IOException {
  @SuppressWarnings("IOResourceOpenedButNotSafelyClosed") InputStream stream = loader.getResourceAsStream(templateName);
  if (stream == null) {
    throw new IOException("Template '" + templateName + "' not found by " + loader);
  }

  String template = FileUtil.loadTextAndClose(new InputStreamReader(stream, CharsetToolkit.UTF8));
  if (variables == null || variables.size() == 0) {
    return template;
  }

  StringBuilder buffer = new StringBuilder(template);
  for (Map.Entry<String, String> var : variables.entrySet()) {
    String name = var.getKey();
    int pos = buffer.indexOf(name);
    if (pos >= 0) {
      buffer.replace(pos, pos + name.length(), var.getValue());
    }
  }
  return buffer.toString();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:ExecUtil.java

示例10: executeMethod

import com.intellij.openapi.vfs.CharsetToolkit; //导入依赖的package包/类
private String executeMethod(HttpMethod method) throws Exception {
  String responseBody;
  getHttpClient().executeMethod(method);
  Header contentType = method.getResponseHeader("Content-Type");
  if (contentType != null && contentType.getValue().contains("charset")) {
    // ISO-8859-1 if charset wasn't specified in response
    responseBody = StringUtil.notNullize(method.getResponseBodyAsString());
  }
  else {
    InputStream stream = method.getResponseBodyAsStream();
    responseBody = stream == null ? "" : StreamUtil.readText(stream, CharsetToolkit.UTF8_CHARSET);
  }
  if (method.getStatusCode() != HttpStatus.SC_OK) {
    throw new Exception("Request failed with HTTP error: " + method.getStatusText());
  }
  return responseBody;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:GenericRepository.java

示例11: setupFileEditorAndDocument

import com.intellij.openapi.vfs.CharsetToolkit; //导入依赖的package包/类
@NotNull
private static Document setupFileEditorAndDocument(@NotNull String fileName, @NotNull String fileText) throws IOException {
  EncodingProjectManager.getInstance(getProject()).setEncoding(null, CharsetToolkit.UTF8_CHARSET);
  EncodingProjectManager.getInstance(ProjectManager.getInstance().getDefaultProject()).setEncoding(null, CharsetToolkit.UTF8_CHARSET);
  PostprocessReformattingAspect.getInstance(ourProject).doPostponedFormatting();
  deleteVFile();
  myVFile = getSourceRoot().createChildData(null, fileName);
  VfsUtil.saveText(myVFile, fileText);
  final FileDocumentManager manager = FileDocumentManager.getInstance();
  final Document document = manager.getDocument(myVFile);
  assertNotNull("Can't create document for '" + fileName + "'", document);
  manager.reloadFromDisk(document);
  document.insertString(0, " ");
  document.deleteString(0, 1);
  myFile = getPsiManager().findFile(myVFile);
  assertNotNull("Can't create PsiFile for '" + fileName + "'. Unknown file type most probably.", myFile);
  assertTrue(myFile.isPhysical());
  myEditor = createEditor(myVFile);
  myVFile.setCharset(CharsetToolkit.UTF8_CHARSET);

  PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
  return document;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:LightPlatformCodeInsightTestCase.java

示例12: 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

示例13: saveContext

import com.intellij.openapi.vfs.CharsetToolkit; //导入依赖的package包/类
private synchronized void saveContext(@Nullable String entryName, String zipPostfix, @Nullable String comment) {
  JBZipFile archive = null;
  try {
    archive = getTasksArchive(zipPostfix);
    if (entryName == null) {
      int i = archive.getEntries().size();
      do {
        entryName = "context" + i++;
      } while (archive.getEntry("/" + entryName) != null);
    }
    JBZipEntry entry = archive.getOrCreateEntry("/" + entryName);
    if (comment != null) {
      entry.setComment(comment);
    }
    Element element = new Element("context");
    saveContext(element);
    String s = new XMLOutputter().outputString(element);
    entry.setData(s.getBytes(CharsetToolkit.UTF8_CHARSET));
  }
  catch (IOException e) {
    LOG.error(e);
  }
  finally {
    closeArchive(archive);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:WorkingContextManager.java

示例14: testSaveDocument_DocumentWasChanged

import com.intellij.openapi.vfs.CharsetToolkit; //导入依赖的package包/类
public void testSaveDocument_DocumentWasChanged() throws Exception {
  final VirtualFile file = createFile();
  final long stamp = file.getModificationStamp();
  final Document document = myDocumentManager.getDocument(file);
  assertNotNull(file.toString(), document);
  WriteCommandAction.runWriteCommandAction(myProject, new Runnable() {
    @Override
    public void run() {
      document.insertString(0, "xxx ");
    }
  });


  myDocumentManager.saveDocument(document);
  assertTrue(stamp != file.getModificationStamp());
  assertEquals(document.getModificationStamp(), file.getModificationStamp());
  assertEquals("xxx test", new String(file.contentsToByteArray(), CharsetToolkit.UTF8_CHARSET));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:FileDocumentManagerImplTest.java

示例15: testSaveAllDocuments_DocumentWasChanged

import com.intellij.openapi.vfs.CharsetToolkit; //导入依赖的package包/类
public void testSaveAllDocuments_DocumentWasChanged() throws Exception {
  final VirtualFile file = createFile();
  final long stamp = file.getModificationStamp();
  final Document document = myDocumentManager.getDocument(file);
  assertNotNull(file.toString(), document);
  WriteCommandAction.runWriteCommandAction(myProject, new Runnable() {
    @Override
    public void run() {
      document.insertString(0, "xxx ");
    }
  });

  myDocumentManager.saveAllDocuments();
  assertNotEquals(stamp, file.getModificationStamp());
  assertEquals("xxx test", new String(file.contentsToByteArray(), CharsetToolkit.UTF8_CHARSET));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:FileDocumentManagerImplTest.java


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