[New] Added ComponentConfiguration.getDataOrAbsoluteDir()

This commit is contained in:
Robert von Burg 2020-01-09 11:57:14 +01:00
parent fa389d7072
commit 93cebbde3b
1 changed files with 18 additions and 0 deletions

View File

@ -63,4 +63,22 @@ public class ComponentConfiguration extends AbstractionConfiguration {
public File getDataFile(String key, String defValue, boolean checkExists) {
return super.getDataFile(key, defValue, getRuntimeConfiguration(), checkExists);
}
public File getDataOrAbsoluteDir(String key, String defValue, boolean writeable) {
String path = getString(key, defValue);
// check for import directory
File pathF = new File(path);
if (!pathF.isAbsolute())
return getDataDir(key, defValue, true);
if (!pathF.exists() || !pathF.isDirectory() || (writeable ? !pathF.canWrite() : !pathF.canRead()))
throw new IllegalStateException("The path " + path + " for key " + key + " is not a directory or " + (
writeable ?
"writeable" :
"readable") + "!");
return pathF;
}
}