From: David ‘Bombe’ Roden Date: Tue, 9 Apr 2013 20:54:07 +0000 (+0200) Subject: Write output to a given writer, not only stdout. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=36b0afc82542273a238c1464abe8790aa85aed93;p=xudocci.git Write output to a given writer, not only stdout. --- 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(); } }