diff --git a/src/main/org/apache/tools/ant/util/LineOrientedOutputStream.java b/src/main/org/apache/tools/ant/util/LineOrientedOutputStream.java index 6f15defc1..3c0df4d9e 100644 --- a/src/main/org/apache/tools/ant/util/LineOrientedOutputStream.java +++ b/src/main/org/apache/tools/ant/util/LineOrientedOutputStream.java @@ -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 * processLine * @throws IOException if there is an error. */ protected void processBuffer() throws IOException { try { - processLine(buffer.toString()); + processLine(buffer.toByteArray()); } finally { buffer.reset(); } @@ -90,6 +90,23 @@ public abstract class LineOrientedOutputStream extends OutputStream { */ protected abstract void processLine(String line) throws IOException; + /** + * Processes a line. + * + *

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.

+ * + * @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 * @throws IOException if there is an error. diff --git a/src/main/org/apache/tools/ant/util/LineOrientedOutputStreamRedirector.java b/src/main/org/apache/tools/ant/util/LineOrientedOutputStreamRedirector.java index 6a8fbf96e..6ce302de2 100644 --- a/src/main/org/apache/tools/ant/util/LineOrientedOutputStreamRedirector.java +++ b/src/main/org/apache/tools/ant/util/LineOrientedOutputStreamRedirector.java @@ -33,10 +33,21 @@ public class LineOrientedOutputStreamRedirector extends LineOrientedOutputStream { 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) { this.stream = stream; } + protected void processLine(byte[] b) throws IOException { + stream.write(b); + stream.write(EOL); + } + protected void processLine(String line) throws IOException { stream.write((line + System.getProperty("line.separator")).getBytes()); }