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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user