From 36b0afc82542273a238c1464abe8790aa85aed93 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 9 Apr 2013 22:54:07 +0200 Subject: [PATCH] Write output to a given writer, not only stdout. --- .../net/pterodactylus/xdcc/ui/stdin/CommandReader.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/pterodactylus/xdcc/ui/stdin/CommandReader.java b/src/main/java/net/pterodactylus/xdcc/ui/stdin/CommandReader.java index 59cdea8..17d2389 100644 --- a/src/main/java/net/pterodactylus/xdcc/ui/stdin/CommandReader.java +++ b/src/main/java/net/pterodactylus/xdcc/ui/stdin/CommandReader.java @@ -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(); } } -- 2.7.4