diff --git a/src/main/java/net/knarcraft/ffmpegconverter/utility/OutputUtil.java b/src/main/java/net/knarcraft/ffmpegconverter/utility/OutputUtil.java new file mode 100644 index 0000000..efe3413 --- /dev/null +++ b/src/main/java/net/knarcraft/ffmpegconverter/utility/OutputUtil.java @@ -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

The debug message to show.

+ */ + public static void setDebug(boolean debug) { + OutputUtil.debug = debug; + } + + /** + * Prints something and a newline to the commandline efficiently + * @param input

The text to print.

+ * @throws IOException

If a write is not possible.

+ */ + public static void println(String input) throws IOException { + if (!input.equals("")) { + writer.write(input); + } + println(); + } + + /** + * Prints a string + * @param input

The string to print.

+ * @throws IOException

If the writer fails to write.

+ */ + public static void print(String input) throws IOException { + writer.write(input); + writer.flush(); + } + + + /** + * Prints a newline + * @throws IOException

If a write is not possible.

+ */ + public static void println() throws IOException { + writer.newLine(); + writer.flush(); + } + + /** + * Closes the writer + * @throws IOException

If the writer cannot be closed.

+ */ + public static void close() throws IOException { + writer.close(); + } + + /** + * Prints a message if debug messages should be shown + * @param message

The debug message to show.

+ * @throws IOException

If a write is not possible.

+ */ + public static void printDebug(String message) throws IOException { + if (debug) { + print(message); + } + } +}