Minor refactoring for tool tasks

- Don't scan for translations on initialization in TranslationPageGenerator in order to speed up startup time of ToolsRunner
- Extract checking for null / empty array of File#listFiles into a separate method
- Move single method of RuntimeUtils into Utils class
This commit is contained in:
ljacqu
2016-10-30 10:43:59 +01:00
parent 195e409efd
commit 46af922fba
10 changed files with 45 additions and 58 deletions
@@ -1,5 +1,6 @@
package tools.utils;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@@ -62,4 +63,19 @@ public final class FileIoUtils {
}
}
/**
* Returns a folder's files or throws an exception if the folder could not be read or if it is empty.
*
* @param folder the folder to read
* @return the files in the folder
*/
public static File[] listFilesOrThrow(File folder) {
File[] files = folder.listFiles();
if (files == null) {
throw new IllegalStateException("Could not read folder '" + folder + "'");
} else if (files.length == 0) {
throw new IllegalStateException("Folder '" + folder + "' is empty");
}
return files;
}
}