Printing output of signature generation into a log file.
[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      * Invoke {@link PrintWriter#println(Object)} passing {@code line} as argument while also printing {@code line} to
33      * standard output if {@code duplicateToStdOut} is {@code true}.
34      * @param line The line to be printed.
35      * @param writer The {@link PrintWriter} that is to print {@code line}.
36      * @param duplicateToStdOut Set to {@code true} if {@code line} should also be printed in standard output.
37      */
38     public static void print(Object line, PrintWriter writer, boolean duplicateToStdOut) {
39         if (duplicateToStdOut) {
40             System.out.print(line);
41         }
42         writer.print(line);
43     }
44
45     /**
46      * Make writer (and standard output, if {@code duplicateToStdOut} is {@code true}) print an empty line.
47      * @param writer The writer that {@link PrintWriter#println()} is to be invoked on.
48      * @param duplicateToStdOut If {@code true}, prints an empty line to standard output.
49      */
50     public static void printEmptyLine(PrintWriter writer, boolean duplicateToStdOut) {
51         if (duplicateToStdOut) {
52             System.out.println();
53         }
54         writer.println();
55     }
56
57 }