diff options
author | Sarika Sinha | 2017-03-04 13:27:55 +0000 |
---|---|---|
committer | Sarika Sinha | 2017-03-04 13:27:55 +0000 |
commit | f8b78f2946e2965bc5bcd90c199e3982e844a831 (patch) | |
tree | 71df3906aa9f25a810aa7f66191c079ec3166c85 /org.eclipse.ui.console | |
parent | fd0dda7c8cf10980c2b9e0f2e83d640d8455f7b9 (diff) | |
download | eclipse.platform.debug-f8b78f2946e2965bc5bcd90c199e3982e844a831.tar.gz eclipse.platform.debug-f8b78f2946e2965bc5bcd90c199e3982e844a831.tar.xz eclipse.platform.debug-f8b78f2946e2965bc5bcd90c199e3982e844a831.zip |
Bug 507664 - IOConsoleOutputStream does not handle multi-byte charactersY20170309-1000S4_7_0_M6I20170308-2000I20170308-0800I20170307-2000I20170307-0800I20170307-0610I20170307-0450I20170307-0420I20170307-0410I20170307-0150I20170306-2000I20170306-0800I20170305-2000I20170304-2000
at buffer boundaries correctly
Change-Id: Iee66ccfd74f93760b1c0e26c7114d4b48cee6324
Diffstat (limited to 'org.eclipse.ui.console')
-rw-r--r-- | org.eclipse.ui.console/src/org/eclipse/ui/console/IOConsoleOutputStream.java | 15 | ||||
-rw-r--r-- | org.eclipse.ui.console/src/org/eclipse/ui/internal/console/StreamDecoder.java | 21 |
2 files changed, 25 insertions, 11 deletions
diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/console/IOConsoleOutputStream.java b/org.eclipse.ui.console/src/org/eclipse/ui/console/IOConsoleOutputStream.java index 7e78ddf6a..8ee47071f 100644 --- a/org.eclipse.ui.console/src/org/eclipse/ui/console/IOConsoleOutputStream.java +++ b/org.eclipse.ui.console/src/org/eclipse/ui/console/IOConsoleOutputStream.java @@ -168,10 +168,15 @@ public class IOConsoleOutputStream extends OutputStream { // Closeable#close() has no effect if already closed return; } + StringBuilder builder = new StringBuilder(); if (prependCR) { // force writing of last /r prependCR = false; - notifyParitioner("\r"); //$NON-NLS-1$ + builder.append('\r'); } + this.decoder.finish(builder); + if (builder.length() > 0) { + notifyParitioner(builder.toString()); + } console.streamClosed(this); closed = true; partitioner = null; @@ -193,7 +198,7 @@ public class IOConsoleOutputStream extends OutputStream { * @see java.io.OutputStream#write(byte[], int, int) */ @Override - public void write(byte[] b, int off, int len) throws IOException { + public synchronized void write(byte[] b, int off, int len) throws IOException { StringBuilder builder = new StringBuilder(); this.decoder.decode(builder, b, off, len); encodedWrite(builder.toString()); @@ -317,10 +322,12 @@ public class IOConsoleOutputStream extends OutputStream { * @throws IOException if the stream is closed * @since 3.7 */ - public void setCharset(Charset charset) throws IOException { + public synchronized void setCharset(Charset charset) throws IOException { StringBuilder builder = new StringBuilder(); this.decoder.finish(builder); - this.encodedWrite(builder.toString()); + if (builder.length() > 0) { + this.encodedWrite(builder.toString()); + } this.decoder = new StreamDecoder(charset); } diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/StreamDecoder.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/StreamDecoder.java index dde14fdcd..aeb0179f1 100644 --- a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/StreamDecoder.java +++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/StreamDecoder.java @@ -29,6 +29,7 @@ public class StreamDecoder { private final CharsetDecoder decoder; private final ByteBuffer inputBuffer; private final CharBuffer outputBuffer; + private boolean finished; public StreamDecoder(Charset charset) { this.decoder = charset.newDecoder(); @@ -37,6 +38,7 @@ public class StreamDecoder { this.inputBuffer = ByteBuffer.allocate(StreamDecoder.BUFFER_SIZE); this.inputBuffer.flip(); this.outputBuffer = CharBuffer.allocate(StreamDecoder.BUFFER_SIZE); + this.finished = false; } private void consume(StringBuilder consumer) { @@ -45,15 +47,15 @@ public class StreamDecoder { this.outputBuffer.clear(); } - private void internalDecode(StringBuilder consumer, byte[] buffer, int offset, int length, boolean last) { + private void internalDecode(StringBuilder consumer, byte[] buffer, int offset, int length) { assert (offset >= 0); assert (length >= 0); int position = offset; int end = offset + length; assert (end <= buffer.length); - boolean finished = false; + boolean finishedReading = false; do { - CoderResult result = this.decoder.decode(this.inputBuffer, this.outputBuffer, last); + CoderResult result = this.decoder.decode(this.inputBuffer, this.outputBuffer, false); if (result.isOverflow()) { this.consume(consumer); } else if (result.isUnderflow()) { @@ -65,23 +67,28 @@ public class StreamDecoder { this.inputBuffer.put(buffer, position, read); position += read; } else { - finished = true; + finishedReading = true; } this.inputBuffer.flip(); } else { assert false; } - } while (!finished); + } while (!finishedReading); } public void decode(StringBuilder consumer, byte[] buffer, int offset, int length) { - this.internalDecode(consumer, buffer, offset, length, false); + this.internalDecode(consumer, buffer, offset, length); this.consume(consumer); } public void finish(StringBuilder consumer) { - this.internalDecode(consumer, new byte[0], 0, 0, true); + if (this.finished) { + return; + } + this.finished = true; CoderResult result; + result = this.decoder.decode(this.inputBuffer, this.outputBuffer, true); + assert (result.isOverflow() || result.isUnderflow()); do { result = this.decoder.flush(this.outputBuffer); if (result.isOverflow()) { |