Adds a new class for loading converter arguments

This commit is contained in:
Kristian Knarvik 2021-01-25 22:05:16 +01:00
parent d6754b61cb
commit 1e3544f793
2 changed files with 60 additions and 0 deletions

View File

@ -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<ConverterArgument> 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 <p>The loaded converter arguments.</p>
*/
List<ConverterArgument> getConverterArguments() {
return new ArrayList<>(this.converterArguments);
}
/**
* Loads all converter arguments
* @throws IOException <p>If unable to read the converter argument file.</p>
*/
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])));
}
}
}

View File

@ -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());
}
}