Java Code Examples for com.intellij.openapi.vfs.CharsetToolkit#UTF8_CHARSET
The following examples show how to use
com.intellij.openapi.vfs.CharsetToolkit#UTF8_CHARSET .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpRequests.java From consulo with Apache License 2.0 | 6 votes |
private static Charset getCharset(Request request) throws IOException { String contentType = request.getConnection().getContentType(); if (!StringUtil.isEmptyOrSpaces(contentType)) { Matcher m = CHARSET_PATTERN.matcher(contentType); if (m.find()) { try { return Charset.forName(StringUtil.unquoteString(m.group(1))); } catch (IllegalArgumentException e) { throw new IOException("unknown charset (" + contentType + ")", e); } } } return CharsetToolkit.UTF8_CHARSET; }
Example 2
Source File: FTManager.java From consulo with Apache License 2.0 | 6 votes |
/** 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(); }
Example 3
Source File: ThriftBuilder.java From intellij-thrift with Apache License 2.0 | 5 votes |
private void compileFile(final CompileContext context, ModuleBuildTarget target, List<String> line, File source, File dir) throws StopBuildException { final JpsModule module = target.getModule(); List<String> cmdLine = new ArrayList<String>(line); cmdLine.add(source.getAbsolutePath()); StringBuilder cmdMessage = new StringBuilder(); for (String cmdPart : cmdLine) { cmdMessage.append(cmdPart).append(' '); } context.processMessage( new CompilerMessage(getPresentableName(), BuildMessage.Kind.INFO, cmdMessage.toString()) ); try { Process process = new ProcessBuilder() .command(cmdLine) .start(); BaseOSProcessHandler handler = new BaseOSProcessHandler(process, StringUtil.join(cmdLine, " "), CharsetToolkit.UTF8_CHARSET); final AtomicBoolean hasErrors = new AtomicBoolean(); handler.addProcessListener(new ThriftOutputConsumer(source.getAbsolutePath(), context, hasErrors, module, dir)); handler.startNotify(); handler.waitFor(); if (hasErrors.get()) { throw new StopBuildException(); } } catch (IOException e) { context.processMessage( new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, "Failed to translate files . Error: " + e.getMessage()) ); } }
Example 4
Source File: StateMap.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private static byte[] archiveState(@Nonnull Element state) { BufferExposingByteArrayOutputStream byteOut = new BufferExposingByteArrayOutputStream(); try { try (OutputStreamWriter writer = new OutputStreamWriter(new SnappyOutputStream(byteOut), CharsetToolkit.UTF8_CHARSET)) { XMLOutputter xmlOutputter = JDOMUtil.newXmlOutputter(); xmlOutputter.setFormat(XML_FORMAT); xmlOutputter.output(state, writer); } } catch (IOException e) { throw new StateStorageException(e); } return ArrayUtil.realloc(byteOut.getInternalBuffer(), byteOut.size()); }
Example 5
Source File: JDOMUtil.java From consulo with Apache License 2.0 | 5 votes |
public static void writeParent(@Nonnull Parent element, @Nonnull OutputStream stream, @Nonnull String lineSeparator) throws IOException { OutputStreamWriter writer = new OutputStreamWriter(stream, CharsetToolkit.UTF8_CHARSET); try { if (element instanceof Document) { writeDocument((Document)element, writer, lineSeparator); } else { writeElement((Element)element, writer, lineSeparator); } } finally { writer.close(); } }
Example 6
Source File: ShelveChangesManager.java From consulo with Apache License 2.0 | 5 votes |
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); } }
Example 7
Source File: CompoundShelfFileProcessor.java From consulo with Apache License 2.0 | 5 votes |
public void savePathFile(@Nonnull ContentProvider contentProvider, @Nonnull final File patchPath, @Nonnull CommitContext commitContext) throws IOException { OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(patchPath), CharsetToolkit.UTF8_CHARSET); try { contentProvider.writeContentTo(writer, commitContext); } finally { writer.close(); } }
Example 8
Source File: ExportToHTMLManager.java From consulo with Apache License 2.0 | 5 votes |
@SuppressWarnings({"HardCodedStringLiteral"}) @RequiredReadAction 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 = PsiPackageHelper.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); } }