You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2010/03/15 15:24:21 UTC
svn commit: r923249 - in /pivot/trunk/core/src/org/apache/pivot/io:
EchoReader.java EchoWriter.java
Author: gbrown
Date: Mon Mar 15 14:24:21 2010
New Revision: 923249
URL: http://svn.apache.org/viewvc?rev=923249&view=rev
Log:
Make echo writer configurable (default to console).
Modified:
pivot/trunk/core/src/org/apache/pivot/io/EchoReader.java
pivot/trunk/core/src/org/apache/pivot/io/EchoWriter.java
Modified: pivot/trunk/core/src/org/apache/pivot/io/EchoReader.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/io/EchoReader.java?rev=923249&r1=923248&r2=923249&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/io/EchoReader.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/io/EchoReader.java Mon Mar 15 14:24:21 2010
@@ -17,31 +17,44 @@
package org.apache.pivot.io;
import java.io.IOException;
+import java.io.PrintWriter;
import java.io.Reader;
+import java.io.Writer;
/**
* Reader that echoes characters to the console as they are read.
*/
public class EchoReader extends Reader {
- private Reader reader;
+ private Reader in;
+ private Writer echo;
- public EchoReader(Reader reader) {
- if (reader == null) {
+ public EchoReader(Reader in) {
+ this(in, new PrintWriter(System.out));
+ }
+
+ public EchoReader(Reader in, Writer echo) {
+ if (in == null) {
+ throw new IllegalArgumentException();
+ }
+
+ if (echo == null) {
throw new IllegalArgumentException();
}
- this.reader = reader;
+ this.in = in;
+ this.echo = echo;
}
@Override
public void close() throws IOException {
- reader.close();
+ in.close();
}
@Override
public int read(char[] cbuf, int off, int len) throws IOException {
- int n = reader.read(cbuf, off, len);
- System.out.print(cbuf);
+ int n = in.read(cbuf, off, len);
+ echo.write(cbuf, off, len);
+
return n;
}
}
Modified: pivot/trunk/core/src/org/apache/pivot/io/EchoWriter.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/io/EchoWriter.java?rev=923249&r1=923248&r2=923249&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/io/EchoWriter.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/io/EchoWriter.java Mon Mar 15 14:24:21 2010
@@ -17,35 +17,46 @@
package org.apache.pivot.io;
import java.io.IOException;
+import java.io.PrintWriter;
import java.io.Writer;
/**
* Writer that echoes characters to the console as they are written.
*/
public class EchoWriter extends Writer {
- private Writer writer;
+ private Writer out;
+ private Writer echo;
- public EchoWriter(Writer writer) {
- if (writer == null) {
+ public EchoWriter(Writer out) {
+ this(out, new PrintWriter(System.out));
+ }
+
+ public EchoWriter(Writer out, Writer echo) {
+ if (out == null) {
+ throw new IllegalArgumentException();
+ }
+
+ if (echo == null) {
throw new IllegalArgumentException();
}
- this.writer = writer;
+ this.out = out;
+ this.echo = echo;
}
@Override
public void close() throws IOException {
- writer.close();
+ out.close();
}
@Override
public void flush() throws IOException {
- writer.flush();
+ out.flush();
}
@Override
public void write(char[] cbuf, int off, int len) throws IOException {
- System.out.print(cbuf);
- writer.write(cbuf, off, len);
+ out.write(cbuf, off, len);
+ echo.write(cbuf, off, len);
}
}