Author: bodewig
Date: Sun Dec 4 10:45:52 2011
New Revision: 1210088
URL: http://svn.apache.org/viewvc?rev=1210088&view=rev
Log:
LineOrientedOutputStream breaks encoding, this is the reason why the fix for PR
50507 broke outputencoding in <exec>. PR 52283
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/util/LineOrientedOutputStream.java
ant/core/trunk/src/main/org/apache/tools/ant/util/LineOrientedOutputStreamRedirector.java
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/util/LineOrientedOutputStream.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/LineOrientedOutputStream.java?rev=1210088&r1=1210087&r2=1210088&view=diff
==============================================================================
---
ant/core/trunk/src/main/org/apache/tools/ant/util/LineOrientedOutputStream.java
(original)
+++
ant/core/trunk/src/main/org/apache/tools/ant/util/LineOrientedOutputStream.java
Sun Dec 4 10:45:52 2011
@@ -70,13 +70,13 @@ public abstract class LineOrientedOutput
}
/**
- * Converts the buffer to a string and sends it to
+ * Converts the buffer to a byte[] and sends it to
* <code>processLine</code>
* @throws IOException if there is an error.
*/
protected void processBuffer() throws IOException {
try {
- processLine(buffer.toString());
+ processLine(buffer.toByteArray());
} finally {
buffer.reset();
}
@@ -91,6 +91,23 @@ public abstract class LineOrientedOutput
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
* @throws IOException if there is an error.
*/
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/util/LineOrientedOutputStreamRedirector.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/LineOrientedOutputStreamRedirector.java?rev=1210088&r1=1210087&r2=1210088&view=diff
==============================================================================
---
ant/core/trunk/src/main/org/apache/tools/ant/util/LineOrientedOutputStreamRedirector.java
(original)
+++
ant/core/trunk/src/main/org/apache/tools/ant/util/LineOrientedOutputStreamRedirector.java
Sun Dec 4 10:45:52 2011
@@ -33,10 +33,21 @@ public class LineOrientedOutputStreamRed
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());
}