use of exceptions.InvalidConfigException in project ASCIIGenome by dariober.
the class InteractiveInput method setConfigOpt.
private void setConfigOpt(List<String> cmdTokens) throws IOException, InvalidConfigException, InvalidCommandLineException, InvalidColourException {
List<String> args = new ArrayList<String>(cmdTokens);
args.remove(0);
if (args.size() == 0) {
throw new InvalidCommandLineException();
}
if (args.size() == 1) {
ConfigKey key = ConfigKey.getConfigKeyFromShort(args.get(0));
if (ConfigKey.booleanKeys().contains(key)) {
// If configkey is a type boolean, just flip the boolean
key = ConfigKey.valueOf(key.toString());
boolean value = !Utils.asBoolean(Config.get(key));
Config.set(key, String.valueOf(value));
} else {
// configKey is expected to be the name of a configuration file
new Config(args.get(0));
}
} else {
ConfigKey key = ConfigKey.getConfigKeyFromShort(args.get(0));
String value = args.get(1);
try {
Config.set(key, value);
} catch (Exception e) {
throw new InvalidConfigException();
}
}
}
use of exceptions.InvalidConfigException in project ASCIIGenome by dariober.
the class Config method getConfigFileAsString.
private static String getConfigFileAsString(String source) throws IOException, InvalidConfigException {
String rawConfigFile = "";
// Is source null or empty string?
if (source == null || source.isEmpty()) {
// See if default config file exists
File def = new File(System.getProperty("user.home"), ".asciigenome_config");
if (def.isFile()) {
rawConfigFile = FileUtils.readFileToString(def, "UTF-8");
} else {
// If not, read from resource
InputStream res = Config.class.getResourceAsStream("/config/black_on_white.conf");
rawConfigFile = IOUtils.toString(res, "UTF-8");
}
return rawConfigFile;
}
source = Utils.tildeToHomeDir(source);
// Is source a local file? E.g. /path/to/my.conf
if ((new File(source)).isFile()) {
rawConfigFile = FileUtils.readFileToString(new File(source), "UTF-8");
return rawConfigFile;
}
// Is source a tag matching a configuration file in resources? E.g. "black_on_white"
try {
InputStream res = Config.class.getResourceAsStream("/config/" + source + ".conf");
rawConfigFile = IOUtils.toString(res, "UTF-8");
return rawConfigFile;
} catch (Exception e) {
//
}
throw new InvalidConfigException();
}
Aggregations