Browse Source

LineOrientedOutputStream breaks encoding, this is the reason why the fix for PR 50507 broke outputencoding in <exec>. PR 52283

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1210088 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 13 years ago
parent
commit
6000b81daa
2 changed files with 30 additions and 2 deletions
  1. +19
    -2
      src/main/org/apache/tools/ant/util/LineOrientedOutputStream.java
  2. +11
    -0
      src/main/org/apache/tools/ant/util/LineOrientedOutputStreamRedirector.java

+ 19
- 2
src/main/org/apache/tools/ant/util/LineOrientedOutputStream.java View File

@@ -70,13 +70,13 @@ public abstract class LineOrientedOutputStream extends OutputStream {
} }


/** /**
* Converts the buffer to a string and sends it to
* Converts the buffer to a byte[] and sends it to
* <code>processLine</code> * <code>processLine</code>
* @throws IOException if there is an error. * @throws IOException if there is an error.
*/ */
protected void processBuffer() throws IOException { protected void processBuffer() throws IOException {
try { try {
processLine(buffer.toString());
processLine(buffer.toByteArray());
} finally { } finally {
buffer.reset(); buffer.reset();
} }
@@ -90,6 +90,23 @@ public abstract class LineOrientedOutputStream extends OutputStream {
*/ */
protected abstract void processLine(String line) throws IOException; protected abstract void processLine(String line) throws IOException;


/**
* Processes a line.
*
* <p>This implementations invokes the string-arg version
* converting the byte array using the default encoding.
* Subclasses are encouraged to override this method (and provide
* a dummy implementation of the String-arg version) so they don't
* interfere with the encoding of the underlying stream.</p>
*
* @param line the line to log.
* @throws IOException if there is an error.
* @since Ant 1.8.3
*/
protected void processLine(byte[] line) throws IOException {
processLine(new String(line));
}

/** /**
* Writes all remaining * Writes all remaining
* @throws IOException if there is an error. * @throws IOException if there is an error.


+ 11
- 0
src/main/org/apache/tools/ant/util/LineOrientedOutputStreamRedirector.java View File

@@ -33,10 +33,21 @@ public class LineOrientedOutputStreamRedirector
extends extends
LineOrientedOutputStream { LineOrientedOutputStream {
private OutputStream stream; private OutputStream stream;

// these should be in the ASCII range and hopefully are single bytes
// (for LF and CR respectively) for any encoding thrown at this class
private static final byte[] EOL =
System.getProperty("line.separator").getBytes();

public LineOrientedOutputStreamRedirector(OutputStream stream) { public LineOrientedOutputStreamRedirector(OutputStream stream) {
this.stream = stream; this.stream = stream;
} }
protected void processLine(byte[] b) throws IOException {
stream.write(b);
stream.write(EOL);
}
protected void processLine(String line) throws IOException { protected void processLine(String line) throws IOException {
stream.write((line + System.getProperty("line.separator")).getBytes()); stream.write((line + System.getProperty("line.separator")).getBytes());
} }


Loading…
Cancel
Save