diff options
Diffstat (limited to 'org.eclipse.debug.core')
4 files changed, 41 insertions, 25 deletions
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/core/model/RuntimeProcess.java b/org.eclipse.debug.core/core/org/eclipse/debug/core/model/RuntimeProcess.java index e731732cb..8ee0a099d 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/core/model/RuntimeProcess.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/core/model/RuntimeProcess.java @@ -14,6 +14,9 @@ package org.eclipse.debug.core.model; +import java.nio.charset.Charset; +import java.nio.charset.IllegalCharsetNameException; +import java.nio.charset.UnsupportedCharsetException; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -281,7 +284,15 @@ public class RuntimeProcess extends PlatformObject implements IProcess { return new NullStreamsProxy(getSystemProcess()); } String encoding = getLaunch().getAttribute(DebugPlugin.ATTR_CONSOLE_ENCODING); - return new StreamsProxy(getSystemProcess(), encoding); + Charset charset = null; + if (encoding != null) { + try { + charset = Charset.forName(encoding); + } catch (UnsupportedCharsetException | IllegalCharsetNameException e) { + DebugPlugin.log(e); + } + } + return new StreamsProxy(getSystemProcess(), charset); } /** diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/InputStreamMonitor.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/InputStreamMonitor.java index 199b183d8..94e2fb733 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/InputStreamMonitor.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/InputStreamMonitor.java @@ -16,6 +16,7 @@ package org.eclipse.debug.internal.core; import java.io.IOException; import java.io.OutputStream; +import java.nio.charset.Charset; import java.util.Vector; import org.eclipse.debug.core.DebugPlugin; @@ -52,9 +53,9 @@ public class InputStreamMonitor { private boolean fClosed = false; /** - * The encoding of the input stream. + * The charset of the input stream. */ - private String fEncoding; + private Charset fCharset; /** * Creates an input stream monitor which writes to system in via the given output stream. @@ -66,16 +67,17 @@ public class InputStreamMonitor { } /** - * Creates an input stream monitor which writes to system in via the given output stream. + * Creates an input stream monitor which writes to system in via the given + * output stream. * * @param stream output stream - * @param encoding stream encoding or <code>null</code> for system default + * @param charset stream charset or <code>null</code> for system default */ - public InputStreamMonitor(OutputStream stream, String encoding) { - fStream= stream; + public InputStreamMonitor(OutputStream stream, Charset charset) { + fStream = stream; fQueue = new Vector<>(); - fLock= new Object(); - fEncoding= encoding; + fLock = new Object(); + fCharset = charset; } /** @@ -139,8 +141,8 @@ public class InputStreamMonitor { String text = fQueue.firstElement(); fQueue.removeElementAt(0); try { - if (fEncoding != null) { - fStream.write(text.getBytes(fEncoding)); + if (fCharset != null) { + fStream.write(text.getBytes(fCharset)); } else { fStream.write(text.getBytes()); } diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/OutputStreamMonitor.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/OutputStreamMonitor.java index 34aa133a8..00daec44d 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/OutputStreamMonitor.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/OutputStreamMonitor.java @@ -18,6 +18,7 @@ import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.nio.charset.Charset; import java.util.concurrent.atomic.AtomicBoolean; import org.eclipse.core.runtime.ISafeRunnable; @@ -74,20 +75,20 @@ public class OutputStreamMonitor implements IFlushableStreamMonitor { private long lastSleep; - private String fEncoding; + private Charset fCharset; private final AtomicBoolean fDone; /** - * Creates an output stream monitor on the - * given stream (connected to system out or err). + * Creates an output stream monitor on the given stream (connected to system + * out or err). * * @param stream input stream to read from - * @param encoding stream encoding or <code>null</code> for system default + * @param charset stream charset or <code>null</code> for system default */ - public OutputStreamMonitor(InputStream stream, String encoding) { + public OutputStreamMonitor(InputStream stream, Charset charset) { fStream = new BufferedInputStream(stream, 8192); - fEncoding = encoding; + fCharset = charset; fContents= new StringBuilder(); fDone = new AtomicBoolean(false); } @@ -149,7 +150,7 @@ public class OutputStreamMonitor implements IFlushableStreamMonitor { long currentTime = lastSleep; char[] chars = new char[BUFFER_SIZE]; int read = 0; - try (InputStreamReader reader = (fEncoding == null ? new InputStreamReader(fStream) : new InputStreamReader(fStream, fEncoding))) { + try (InputStreamReader reader = (fCharset == null ? new InputStreamReader(fStream) : new InputStreamReader(fStream, fCharset))) { while (read >= 0) { try { if (fKilled) { diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/StreamsProxy.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/StreamsProxy.java index 616e79674..19df55e28 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/StreamsProxy.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/StreamsProxy.java @@ -15,6 +15,7 @@ package org.eclipse.debug.internal.core; import java.io.IOException; +import java.nio.charset.Charset; import org.eclipse.debug.core.model.IStreamMonitor; import org.eclipse.debug.core.model.IStreamsProxy; @@ -43,20 +44,21 @@ public class StreamsProxy implements IStreamsProxy, IStreamsProxy2 { * <code>false</code> by default. */ private boolean fClosed; + /** - * Creates a <code>StreamsProxy</code> on the streams - * of the given system process. + * Creates a <code>StreamsProxy</code> on the streams of the given system + * process. * * @param process system process to create a streams proxy on - * @param encoding the process's encoding or <code>null</code> if default + * @param charset the process's charset or <code>null</code> if default */ - public StreamsProxy(Process process, String encoding) { + public StreamsProxy(Process process, Charset charset) { if (process == null) { return; } - fOutputMonitor= new OutputStreamMonitor(process.getInputStream(), encoding); - fErrorMonitor= new OutputStreamMonitor(process.getErrorStream(), encoding); - fInputMonitor= new InputStreamMonitor(process.getOutputStream(), encoding); + fOutputMonitor = new OutputStreamMonitor(process.getInputStream(), charset); + fErrorMonitor = new OutputStreamMonitor(process.getErrorStream(), charset); + fInputMonitor = new InputStreamMonitor(process.getOutputStream(), charset); fOutputMonitor.startMonitoring(); fErrorMonitor.startMonitoring(); fInputMonitor.startMonitoring(); |