Search in sources :

Example 31 with Charset

use of java.nio.charset.Charset in project intellij-community by JetBrains.

the class HgEncodingTest method testUtfMessageInHistoryWithSpecialCharacters.

//test SpecialCharacters in commit message for default EncodingProject settings
public void testUtfMessageInHistoryWithSpecialCharacters() throws HgCommandException, VcsException {
    cd(myRepository);
    String fileName = "file.txt";
    echo(fileName, "lalala");
    Charset charset = HgEncodingUtil.getDefaultCharset(myProject);
    String comment = "öäüß";
    HgRepository hgRepo = HgRepositoryImpl.getInstance(myRepository, myProject, myProject);
    HgCommitCommand commitCommand = new HgCommitCommand(myProject, hgRepo, comment);
    commitCommand.executeInCurrentThread();
    HgLogCommand logCommand = new HgLogCommand(myProject);
    myRepository.refresh(false, true);
    VirtualFile file = myRepository.findChild(fileName);
    assert file != null;
    List<HgFileRevision> revisions = logCommand.execute(new HgFile(myProject, file), 1, false);
    HgFileRevision rev = revisions.get(0);
    assertEquals(new String(comment.getBytes(charset)), rev.getCommitMessage());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgFile(org.zmlx.hg4idea.HgFile) HgCommitCommand(org.zmlx.hg4idea.command.HgCommitCommand) HgFileRevision(org.zmlx.hg4idea.HgFileRevision) Charset(java.nio.charset.Charset) HgRepository(org.zmlx.hg4idea.repo.HgRepository) HgLogCommand(org.zmlx.hg4idea.command.HgLogCommand)

Example 32 with Charset

use of java.nio.charset.Charset in project intellij-community by JetBrains.

the class PythonDebugConsoleCommunication method execInterpreter.

public void execInterpreter(ConsoleCodeFragment code, final Function<InterpreterResponse, Object> callback) {
    if (waitingForInput) {
        final OutputStream processInput = myDebugProcess.getProcessHandler().getProcessInput();
        if (processInput != null) {
            try {
                final Charset defaultCharset = EncodingProjectManager.getInstance(myDebugProcess.getProject()).getDefaultCharset();
                processInput.write((code.getText()).getBytes(defaultCharset));
                processInput.flush();
            } catch (IOException e) {
                LOG.error(e.getMessage());
            }
        }
        myNeedsMore = false;
        waitingForInput = false;
        notifyCommandExecuted(waitingForInput);
    } else {
        exec(new ConsoleCodeFragment(code.getText(), false), new PyDebugCallback<Pair<String, Boolean>>() {

            @Override
            public void ok(Pair<String, Boolean> executed) {
                boolean more = executed.second;
                myNeedsMore = more;
                notifyCommandExecuted(more);
                callback.fun(new InterpreterResponse(more, isWaitingForInput()));
            }

            @Override
            public void error(PyDebuggerException exception) {
                myNeedsMore = false;
                notifyCommandExecuted(false);
                callback.fun(new InterpreterResponse(false, isWaitingForInput()));
            }
        });
    }
}
Also used : OutputStream(java.io.OutputStream) InterpreterResponse(com.jetbrains.python.console.pydev.InterpreterResponse) Charset(java.nio.charset.Charset) IOException(java.io.IOException) PyDebuggerException(com.jetbrains.python.debugger.PyDebuggerException) Pair(com.intellij.openapi.util.Pair)

Example 33 with Charset

use of java.nio.charset.Charset in project intellij-community by JetBrains.

the class PydevConsoleRunner method setCorrectStdOutEncoding.

/**
   * Set command line charset as current project charset.
   * Add required ENV var to Python task to set its stdout charset to current project charset to allow it print correctly.
   *
   * @param commandLine command line
   * @param project     current project
   */
static void setCorrectStdOutEncoding(@NotNull GeneralCommandLine commandLine, @NotNull Project project) {
    final Charset defaultCharset = EncodingProjectManager.getInstance(project).getDefaultCharset();
    commandLine.setCharset(defaultCharset);
    setPythonIOEncoding(commandLine.getEnvironment(), defaultCharset.name());
}
Also used : Charset(java.nio.charset.Charset)

Example 34 with Charset

use of java.nio.charset.Charset in project intellij-community by JetBrains.

the class PydevConsoleRunner method setCorrectStdOutEncoding.

/**
   * Add required ENV var to Python task to set its stdout charset to current project charset to allow it print correctly.
   *
   * @param envs    map of envs to add variable
   * @param project current project
   */
static void setCorrectStdOutEncoding(@NotNull Map<String, String> envs, @NotNull Project project) {
    final Charset defaultCharset = EncodingProjectManager.getInstance(project).getDefaultCharset();
    final String encoding = defaultCharset.name();
    setPythonIOEncoding(setPythonUnbuffered(envs), encoding);
}
Also used : Charset(java.nio.charset.Charset)

Example 35 with Charset

use of java.nio.charset.Charset in project voltdb by VoltDB.

the class CharsetUtil method decoder.

/**
     * Returns a cached thread-local {@link CharsetDecoder} for the specified {@link Charset}.
     *
     * @param charset The specified charset
     * @return The decoder for the specified <code>charset</code>
     */
public static CharsetDecoder decoder(Charset charset) {
    checkNotNull(charset, "charset");
    Map<Charset, CharsetDecoder> map = InternalThreadLocalMap.get().charsetDecoderCache();
    CharsetDecoder d = map.get(charset);
    if (d != null) {
        d.reset().onMalformedInput(CodingErrorAction.REPLACE).onUnmappableCharacter(CodingErrorAction.REPLACE);
        return d;
    }
    d = decoder(charset, CodingErrorAction.REPLACE, CodingErrorAction.REPLACE);
    map.put(charset, d);
    return d;
}
Also used : CharsetDecoder(java.nio.charset.CharsetDecoder) Charset(java.nio.charset.Charset)

Aggregations

Charset (java.nio.charset.Charset)1400 IOException (java.io.IOException)259 Test (org.junit.Test)186 InputStream (java.io.InputStream)114 ByteBuffer (java.nio.ByteBuffer)110 File (java.io.File)104 ArrayList (java.util.ArrayList)102 InputStreamReader (java.io.InputStreamReader)99 HashMap (java.util.HashMap)76 CharBuffer (java.nio.CharBuffer)64 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)57 Map (java.util.Map)57 OutputStreamWriter (java.io.OutputStreamWriter)56 CharsetDecoder (java.nio.charset.CharsetDecoder)55 ByteArrayInputStream (java.io.ByteArrayInputStream)54 List (java.util.List)54 Path (java.nio.file.Path)50 CharsetEncoder (java.nio.charset.CharsetEncoder)49 FileInputStream (java.io.FileInputStream)48 OutputStream (java.io.OutputStream)47