Search in sources :

Example 1 with InvalidConfigException

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();
        }
    }
}
Also used : ConfigKey(coloring.ConfigKey) Config(coloring.Config) ArrayList(java.util.ArrayList) InvalidCommandLineException(exceptions.InvalidCommandLineException) InvalidConfigException(exceptions.InvalidConfigException) InvalidCommandLineException(exceptions.InvalidCommandLineException) InvalidColourException(exceptions.InvalidColourException) InvalidRecordException(exceptions.InvalidRecordException) SQLException(java.sql.SQLException) ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException) InvalidConfigException(exceptions.InvalidConfigException) PatternSyntaxException(java.util.regex.PatternSyntaxException) IOException(java.io.IOException) InvalidGenomicCoordsException(exceptions.InvalidGenomicCoordsException)

Example 2 with 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();
}
Also used : InputStream(java.io.InputStream) InvalidConfigException(exceptions.InvalidConfigException) File(java.io.File) InvalidConfigException(exceptions.InvalidConfigException) IOException(java.io.IOException) InvalidColourException(exceptions.InvalidColourException)

Aggregations

InvalidColourException (exceptions.InvalidColourException)2 InvalidConfigException (exceptions.InvalidConfigException)2 IOException (java.io.IOException)2 Config (coloring.Config)1 ConfigKey (coloring.ConfigKey)1 InvalidCommandLineException (exceptions.InvalidCommandLineException)1 InvalidGenomicCoordsException (exceptions.InvalidGenomicCoordsException)1 InvalidRecordException (exceptions.InvalidRecordException)1 File (java.io.File)1 InputStream (java.io.InputStream)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 ArgumentParserException (net.sourceforge.argparse4j.inf.ArgumentParserException)1