Makes a new utility class containing methods related to output
This commit is contained in:
parent
f1929f39dc
commit
2c3e37d46c
@ -0,0 +1,75 @@
|
||||
package net.knarcraft.ffmpegconverter.utility;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
|
||||
/**
|
||||
* A class which helps with outputting information
|
||||
*/
|
||||
public final class OutputUtil {
|
||||
private static boolean debug;
|
||||
private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
|
||||
|
||||
private OutputUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to show debug messages
|
||||
* @param debug <p>The debug message to show.</p>
|
||||
*/
|
||||
public static void setDebug(boolean debug) {
|
||||
OutputUtil.debug = debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints something and a newline to the commandline efficiently
|
||||
* @param input <p>The text to print.</p>
|
||||
* @throws IOException <p>If a write is not possible.</p>
|
||||
*/
|
||||
public static void println(String input) throws IOException {
|
||||
if (!input.equals("")) {
|
||||
writer.write(input);
|
||||
}
|
||||
println();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a string
|
||||
* @param input <p>The string to print.</p>
|
||||
* @throws IOException <p>If the writer fails to write.</p>
|
||||
*/
|
||||
public static void print(String input) throws IOException {
|
||||
writer.write(input);
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prints a newline
|
||||
* @throws IOException <p>If a write is not possible.</p>
|
||||
*/
|
||||
public static void println() throws IOException {
|
||||
writer.newLine();
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the writer
|
||||
* @throws IOException <p>If the writer cannot be closed.</p>
|
||||
*/
|
||||
public static void close() throws IOException {
|
||||
writer.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a message if debug messages should be shown
|
||||
* @param message <p>The debug message to show.</p>
|
||||
* @throws IOException <p>If a write is not possible.</p>
|
||||
*/
|
||||
public static void printDebug(String message) throws IOException {
|
||||
if (debug) {
|
||||
print(message);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user