本文整理汇总了Java中com.intellij.openapi.vfs.CharsetToolkit.UTF8_CHARSET属性的典型用法代码示例。如果您正苦于以下问题:Java CharsetToolkit.UTF8_CHARSET属性的具体用法?Java CharsetToolkit.UTF8_CHARSET怎么用?Java CharsetToolkit.UTF8_CHARSET使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.intellij.openapi.vfs.CharsetToolkit
的用法示例。
在下文中一共展示了CharsetToolkit.UTF8_CHARSET属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCourse
@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;
}
示例2: load
@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);
}
}
示例3: convertStreamToString
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 "";
}
}
示例4: setUp
@Override
protected void setUp() throws Exception {
super.setUp();
Random random = new Random();
for (int i = 0; i < 1000; i++) {
byte[] bytes = new byte[1000];
random.nextBytes(bytes);
String key = new String(bytes, CharsetToolkit.UTF8_CHARSET);
myKeys.add(key);
}
for (int i = 0; i < 10; i++) {
PersistentHashMap<String, Record> map = createMap(FileUtil.createTempFile("persistent", "map" + i));
myMaps.add(map);
}
PagedFileStorage.StorageLockContext storageLockContext = new PagedFileStorage.StorageLockContext(false);
myEnumerator = new PersistentStringEnumerator(FileUtil.createTempFile("persistent", "enum"), storageLockContext);
myThreadPool = Executors.newFixedThreadPool(myMaps.size() + 1);
}
示例5: saveTemplate
/** Save template to file. If template is new, it is saved to specified directory. Otherwise it is saved to file from which it was read.
* If template was not modified, it is not saved.
* todo: review saving algorithm
*/
private static void saveTemplate(File parentDir, FileTemplateBase template, final String lineSeparator) throws IOException {
final File templateFile = new File(parentDir, encodeFileName(template.getName(), template.getExtension()));
FileOutputStream fileOutputStream;
try {
fileOutputStream = new FileOutputStream(templateFile);
}
catch (FileNotFoundException e) {
// try to recover from the situation 'file exists, but is a directory'
FileUtil.delete(templateFile);
fileOutputStream = new FileOutputStream(templateFile);
}
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, CharsetToolkit.UTF8_CHARSET);
String content = template.getText();
if (!lineSeparator.equals("\n")){
content = StringUtil.convertLineSeparators(content, lineSeparator);
}
outputStreamWriter.write(content);
outputStreamWriter.close();
fileOutputStream.close();
}
示例6: writePatchesToFile
private static void writePatchesToFile(final Project project,
final String path,
final List<FilePatch> remainingPatches,
CommitContext commitContext) {
try {
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(path), CharsetToolkit.UTF8_CHARSET);
try {
UnifiedDiffWriter.write(project, remainingPatches, writer, "\n", commitContext);
}
finally {
writer.close();
}
}
catch (IOException e) {
LOG.error(e);
}
}
示例7: getCharset
@NotNull
static Charset getCharset(@NotNull Request request) throws IOException {
String contentEncoding = request.getConnection().getContentEncoding();
if (contentEncoding != null) {
try {
return Charset.forName(contentEncoding);
}
catch (Exception ignored) {
}
}
return CharsetToolkit.UTF8_CHARSET;
}
示例8: generateIndexHtml
@SuppressWarnings({"HardCodedStringLiteral"})
private static void generateIndexHtml(final PsiDirectory psiDirectory, final boolean recursive, final String outputDirectoryName)
throws FileNotFoundException {
String indexHtmlName = constructOutputDirectory(psiDirectory, outputDirectoryName) + File.separator + "index.html";
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(indexHtmlName), CharsetToolkit.UTF8_CHARSET);
final String title = PsiDirectoryFactory.getInstance(psiDirectory.getProject()).getQualifiedName(psiDirectory, true);
try {
writer.write("<html><head><title>" + title + "</title></head><body>");
if (recursive) {
PsiDirectory[] directories = psiDirectory.getSubdirectories();
for(PsiDirectory directory: directories) {
writer.write("<a href=\"" + directory.getName() + "/index.html\"><b>" + directory.getName() + "</b></a><br />");
}
}
PsiFile[] files = psiDirectory.getFiles();
for(PsiFile file: files) {
if (!(file instanceof PsiBinaryFile)) {
writer.write("<a href=\"" + getHTMLFileName(file) + "\">" + file.getVirtualFile().getName() + "</a><br />");
}
}
writer.write("</body></html>");
writer.close();
}
catch (IOException e) {
LOG.error(e);
}
}
示例9: save
@Override
public void save() throws IOException {
CachedXmlDocumentSet fileSet = EclipseClasspathStorageProvider.getFileCache(module);
AccessToken token = WriteAction.start();
try {
for (String key : modifiedContent.keySet()) {
Element content = modifiedContent.get(key);
String path = fileSet.getParent(key) + '/' + key;
Writer writer = new OutputStreamWriter(StorageUtil.getOrCreateVirtualFile(this, new File(path)).getOutputStream(this), CharsetToolkit.UTF8_CHARSET);
try {
EclipseJDOMUtil.output(content, writer, module.getProject());
}
finally {
writer.close();
}
}
if (deletedContent.isEmpty()) {
return;
}
for (String deleted : deletedContent) {
VirtualFile file = fileSet.getFile(deleted, false);
if (file != null) {
try {
file.delete(this);
}
catch (IOException ignore) {
}
}
}
deletedContent.clear();
}
finally {
token.finish();
}
}
示例10: decryptText
/**
* Encrypt text
*
* @param password the secret key to use
* @param data the bytes to decrypt
* @return encrypted text
*/
public static String decryptText(byte[] password, byte[] data) {
byte[] plain = decryptData(password, data);
int len = ((plain[0] & 0xff) << 24) + ((plain[1] & 0xff) << 16) + ((plain[2] & 0xff) << 8) + (plain[3] & 0xff);
if (len < 0 || len > plain.length - 4) {
throw new IllegalStateException("Unmatched password is used");
}
return new String(plain, 4, len, CharsetToolkit.UTF8_CHARSET);
}
示例11: actionPerformed
public void actionPerformed(AnActionEvent e) {
final Editor editor = CommonDataKeys.EDITOR.getData(DataManager.getInstance().getDataContext(myConsole.getComponent()));
if (editor != null) {
final byte[] content = editor.getDocument().getText().getBytes(CharsetToolkit.UTF8_CHARSET);
final String extension = "xml"; // TODO: get from output type
final VcsVirtualFile file = new VcsVirtualFile("XSLT Output." + extension, content, null, VcsFileSystem.getInstance()) {
@NotNull
@Override
public Charset getCharset() {
return CharsetToolkit.UTF8_CHARSET;
}
};
FileEditorManager.getInstance(CommonDataKeys.PROJECT.getData(e.getDataContext())).openFile(file, true);
}
}
示例12: savePathFile
public void savePathFile(@NotNull ContentProvider contentProvider,
@NotNull final File patchPath,
@NotNull CommitContext commitContext)
throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(patchPath), CharsetToolkit.UTF8_CHARSET);
try {
contentProvider.writeContentTo(writer, commitContext);
}
finally {
writer.close();
}
}
示例13: writeOutput
private synchronized void writeOutput(@NotNull final CommonProblemDescriptor[] descriptions, @NotNull RefEntity refElement) {
final Element parentNode = new Element(InspectionsBundle.message("inspection.problems"));
exportResults(descriptions, refElement, parentNode);
final List list = parentNode.getChildren();
@NonNls final String ext = ".xml";
final String fileName = ourOutputPath + File.separator + myToolWrapper.getShortName() + ext;
final PathMacroManager pathMacroManager = PathMacroManager.getInstance(getContext().getProject());
PrintWriter printWriter = null;
try {
new File(ourOutputPath).mkdirs();
final File file = new File(fileName);
final CharArrayWriter writer = new CharArrayWriter();
if (!file.exists()) {
writer.append("<").append(InspectionsBundle.message("inspection.problems")).append(" " + GlobalInspectionContextBase.LOCAL_TOOL_ATTRIBUTE + "=\"")
.append(Boolean.toString(myToolWrapper instanceof LocalInspectionToolWrapper)).append("\">\n");
}
for (Object o : list) {
final Element element = (Element)o;
pathMacroManager.collapsePaths(element);
JDOMUtil.writeElement(element, writer, "\n");
}
printWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName, true), CharsetToolkit.UTF8_CHARSET)));
printWriter.append("\n");
printWriter.append(writer.toString());
}
catch (IOException e) {
LOG.error(e);
}
finally {
if (printWriter != null) {
printWriter.close();
}
}
}
示例14: createTtyConnector
@Override
protected TtyConnector createTtyConnector(PtyProcess process)
{
return new RocTtyConnector(process, CharsetToolkit.UTF8_CHARSET);
}
示例15: LuaProcessHandler
public LuaProcessHandler(@NotNull Process process, @Nullable String commandLine) {
super(process, CharsetToolkit.UTF8_CHARSET, commandLine);
}