167993de175850a2cbd55ad5da2b1ad26e36dabf
[pingpong.git] / Code / Projects / PacketLevelSignatureExtractor / src / main / java / edu / uci / iotproject / io / PrintWriterUtils.java
1 package edu.uci.iotproject.io;
2
3 import java.io.PrintWriter;
4
5 /**
6  * Utility methods for (jointly) printing to a {@link PrintWriter} (and standard output).
7  *
8  * @author Janus Varmarken {@literal <jvarmark@uci.edu>}
9  * @author Rahmadi Trimananda {@literal <rtrimana@uci.edu>}
10  */
11 public final class PrintWriterUtils {
12
13     private PrintWriterUtils() {
14         // Disallow instantiation. Static-only class.
15     }
16
17     /**
18      * Invoke {@link PrintWriter#println(Object)} passing {@code line} as argument while also printing {@code line} to
19      * standard output if {@code duplicateToStdOut} is {@code true}.
20      * @param line The line to be printed.
21      * @param writer The {@link PrintWriter} that is to print {@code line}.
22      * @param duplicateToStdOut Set to {@code true} if {@code line} should also be printed in standard output.
23      */
24     public static void println(Object line, PrintWriter writer, boolean duplicateToStdOut) {
25         if (duplicateToStdOut) {
26             System.out.println(line);
27         }
28         writer.println(line);
29     }
30
31     /**
32      * Make writer (and standard output, if {@code duplicateToStdOut} is {@code true}) print an empty line.
33      * @param writer The writer that {@link PrintWriter#println()} is to be invoked on.
34      * @param duplicateToStdOut If {@code true}, prints an empty line to standard output.
35      */
36     public static void printEmptyLine(PrintWriter writer, boolean duplicateToStdOut) {
37         if (duplicateToStdOut) {
38             System.out.println();
39         }
40         writer.println();
41     }
42
43 }