Write output to a given writer, not only stdout.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 9 Apr 2013 20:54:07 +0000 (22:54 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 9 Apr 2013 20:56:58 +0000 (22:56 +0200)
src/main/java/net/pterodactylus/xdcc/ui/stdin/CommandReader.java

index 59cdea8..17d2389 100644 (file)
@@ -19,6 +19,7 @@ package net.pterodactylus.xdcc.ui.stdin;
 
 import java.io.BufferedReader;
 import java.io.Reader;
+import java.io.Writer;
 import java.util.Collections;
 import java.util.List;
 
@@ -42,6 +43,9 @@ public class CommandReader extends AbstractExecutionThreadService {
        /** The reader to read commands from. */
        private final BufferedReader reader;
 
+       /** The writer to write the results to. */
+       private final Writer writer;
+
        /**
         * Creates a new command reader.
         *
@@ -49,10 +53,13 @@ public class CommandReader extends AbstractExecutionThreadService {
         *              The core being controlled
         * @param reader
         *              The reader to read commands from
+        * @param writer
+        *              The write to write results to
         */
-       public CommandReader(Core core, Reader reader) {
+       public CommandReader(Core core, Reader reader, Writer writer) {
                this.core = core;
                this.reader = new BufferedReader(reader);
+               this.writer = writer;
        }
 
        //
@@ -92,12 +99,13 @@ public class CommandReader extends AbstractExecutionThreadService {
                                Collections.sort(lastResult);
                                int counter = 0;
                                for (Result result : lastResult) {
-                                       System.out.println(String.format("[%d] %s (%s) from %s (#%s) on %s", counter++, result.pack().name(), result.pack().size(), result.bot().name(), result.pack().id(), result.bot().network().name()));
+                                       writer.write(String.format("[%d] %s (%s) from %s (#%s) on %s\n", counter++, result.pack().name(), result.pack().size(), result.bot().name(), result.pack().id(), result.bot().network().name()));
                                }
-                               System.out.println("End of Search.");
+                               writer.write("End of Search.\n");
                        }
 
                        lastLine = line;
+                       writer.flush();
                }
        }