Example usage for org.apache.commons.compress.utils Charsets toCharset

List of usage examples for org.apache.commons.compress.utils Charsets toCharset

Introduction

In this page you can find the example usage for org.apache.commons.compress.utils Charsets toCharset.

Prototype

public static Charset toCharset(final String charset) 

Source Link

Document

Returns a Charset for the named charset.

Usage

From source file:fr.ens.biologie.genomique.eoulsan.it.ITFactory.java

/**
 * Collect tests to launch from text files with name tests.
 * @return list all directories test found
 * @throws IOException if an error occurs while read file
 */// w w  w .  jav a  2  s  .  c  o m
private List<File> readTestListFile() throws IOException {

    final List<File> result = new ArrayList<>();

    if (this.selectedTestsFile == null) {
        return Collections.emptyList();
    }

    checkExistingStandardFile(this.selectedTestsFile, "selected tests file");

    final BufferedReader br = new BufferedReader(
            newReader(this.selectedTestsFile, Charsets.toCharset(Globals.DEFAULT_FILE_ENCODING)));

    String nameTest;
    while ((nameTest = br.readLine()) != null) {
        // Skip commentary
        if (nameTest.startsWith("#") || nameTest.isEmpty()) {
            continue;
        }

        result.add(new File(this.testsDataDirectory, nameTest.trim()));
    }

    // Close buffer
    br.close();

    return result;
}

From source file:fr.ens.biologie.genomique.eoulsan.it.ITFactory.java

/**
 * Load configuration file in properties object.
 * @param configurationFile configuration file
 * @return properties/* w  w  w  . ja  va 2 s . co  m*/
 * @throws IOException if an error occurs when reading file.
 * @throws EoulsanException if an error occurs evaluate value property.
 */
private static Properties loadProperties(final File configurationFile) throws IOException, EoulsanException {

    // TODO Replace properties by treeMap to use constant in set environment
    // variables
    final Properties rawProps = new Properties();
    final Properties props;

    checkExistingStandardFile(configurationFile, "test configuration file");

    // Load configuration file
    rawProps.load(newReader(configurationFile, Charsets.toCharset(Globals.DEFAULT_FILE_ENCODING)));

    props = evaluateProperties(rawProps);

    // Check include
    final String includeOption = props.getProperty(INCLUDE_CONF_KEY);

    if (includeOption != null) {
        // Check configuration file
        final File otherConfigurationFile = new File(includeOption);

        checkExistingStandardFile(otherConfigurationFile, "configuration file doesn't exist");

        // Load configuration in global configuration
        final Properties rawPropsIncludedConfigurationFile = new Properties();
        rawPropsIncludedConfigurationFile
                .load(newReader(otherConfigurationFile, Charsets.toCharset(Globals.DEFAULT_FILE_ENCODING)));

        final Properties newProps = evaluateProperties(rawPropsIncludedConfigurationFile);

        for (final String propertyName : newProps.stringPropertyNames()) {

            // No overwrite property from includes file configuration
            if (props.containsKey(propertyName)) {
                continue;
            }

            props.put(propertyName, newProps.getProperty(propertyName));
        }
    }

    // Add default value
    addDefaultProperties(props);

    return props;
}

From source file:fr.ens.biologie.genomique.eoulsan.it.IT.java

/**
 * Retrieve properties for the test, compile specific configuration with
 * global./*from   ww w. j a  va 2  s  .c  o  m*/
 * @param globalsConf global configuration for tests
 * @return Properties content of configuration file
 * @throws IOException if an error occurs while reading the file.
 * @throws EoulsanException if an error occurs while evaluating value property
 */
private Properties loadConfigurationFile(final Properties globalsConf) throws IOException, EoulsanException {

    final File testConfFile = new File(this.testDataDirectory, ITFactory.TEST_CONFIGURATION_FILENAME);

    checkExistingFile(testConfFile, "test configuration file");

    // Add global configuration
    final Properties props = new Properties();
    props.putAll(globalsConf);

    final BufferedReader br = newReader(testConfFile, Charsets.toCharset(Globals.DEFAULT_FILE_ENCODING));

    String line = null;

    while ((line = br.readLine()) != null) {
        // Skip commentary
        if (line.startsWith("#")) {
            continue;
        }

        final int pos = line.indexOf('=');
        if (pos == -1) {
            continue;
        }

        final String key = line.substring(0, pos).trim();

        // Evaluate value
        String value = evaluateExpressions(line.substring(pos + 1).trim(), true);

        // Key pattern : add value for test to values from
        // configuration general

        if (isKeyInCompileProperties(key) && props.containsKey(key)) {
            // Concatenate values
            value = props.getProperty(key) + SEPARATOR + value;
        }

        // Save parameter with value
        props.put(key, value);
    }
    br.close();

    return props;

}