From 1e3544f7939f037938c93d9fe34d5a7feff59e6a Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Mon, 25 Jan 2021 22:05:16 +0100 Subject: [PATCH] Adds a new class for loading converter arguments --- .../parser/ConverterArgumentsLoader.java | 46 +++++++++++++++++++ .../parser/ConverterArgumentsLoaderTest.java | 14 ++++++ 2 files changed, 60 insertions(+) create mode 100644 src/main/java/net/knarcraft/ffmpegconverter/parser/ConverterArgumentsLoader.java create mode 100644 src/test/java/net/knarcraft/ffmpegconverter/parser/ConverterArgumentsLoaderTest.java diff --git a/src/main/java/net/knarcraft/ffmpegconverter/parser/ConverterArgumentsLoader.java b/src/main/java/net/knarcraft/ffmpegconverter/parser/ConverterArgumentsLoader.java new file mode 100644 index 0000000..96ef127 --- /dev/null +++ b/src/main/java/net/knarcraft/ffmpegconverter/parser/ConverterArgumentsLoader.java @@ -0,0 +1,46 @@ +package net.knarcraft.ffmpegconverter.parser; + +import net.knarcraft.ffmpegconverter.utility.FileUtil; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +class ConverterArgumentsLoader { + + private List converterArguments; + + /** + * Instantiates a new converter arguments loader and loads converter arguments + */ + ConverterArgumentsLoader() { + this.converterArguments = new ArrayList<>(); + try { + loadConverterArguments(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Gets loaded converter arguments + * @return

The loaded converter arguments.

+ */ + List getConverterArguments() { + return new ArrayList<>(this.converterArguments); + } + + /** + * Loads all converter arguments + * @throws IOException

If unable to read the converter argument file.

+ */ + private void loadConverterArguments() throws IOException { + String[] arguments = FileUtil.readFileLines("converter_arguments.txt"); + for (String argument : arguments) { + String[] argumentFields = argument.split("\\|"); + converterArguments.add(new ConverterArgument(argumentFields[0], argumentFields[1], Boolean.parseBoolean(argumentFields[2]), + ConverterArgumentValue.valueOf(argumentFields[3]))); + } + } + +} diff --git a/src/test/java/net/knarcraft/ffmpegconverter/parser/ConverterArgumentsLoaderTest.java b/src/test/java/net/knarcraft/ffmpegconverter/parser/ConverterArgumentsLoaderTest.java new file mode 100644 index 0000000..aeb78f9 --- /dev/null +++ b/src/test/java/net/knarcraft/ffmpegconverter/parser/ConverterArgumentsLoaderTest.java @@ -0,0 +1,14 @@ +package net.knarcraft.ffmpegconverter.parser; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; + +public class ConverterArgumentsLoaderTest { + + @Test + public void loadTest() { + ConverterArgumentsLoader loader = new ConverterArgumentsLoader(); + assertEquals(14, loader.getConverterArguments().size()); + } + +}