Example usage for java.util Properties load

List of usage examples for java.util Properties load

Introduction

In this page you can find the example usage for java.util Properties load.

Prototype

public synchronized void load(InputStream inStream) throws IOException 

Source Link

Document

Reads a property list (key and element pairs) from the input byte stream.

Usage

From source file:jp.primecloud.auto.tool.management.util.ManagementConfigLoader.java

protected static void loadProp() throws Exception {
    String configPath = Config.getProperty("AUTOCONFIG_PROPERTY_PATH");
    if (configPath == null) {
        throw new RuntimeException(
                MessageUtils.format("Property '{0}' is not found.", "AUTOCONFIG_PROPERTY_PATH"));
    }/*from  w  w w .  j  a  v  a 2  s. c o m*/

    File file = new File(configPath);
    if (!file.exists()) {
        throw new RuntimeException(MessageUtils.format("ConfigFile '{0}' is not found.", configPath));
    }

    Properties properties = ConfigHolder.getProperties();
    try {
        properties.load(new FileInputStream(file));
        ConfigHolder.setProperties(properties);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.bt.aloha.batchtest.WeekendBatchTest.java

protected static void addBatchScenarios(BatchTest batchTest) throws Exception {
    Properties properties = new Properties();
    InputStream is = new FileInputStream(SCENARIO_FILE);
    properties.load(is);
    is.close();//from  w  w  w.  jav a2s .co  m
    for (Object scenarioName : properties.keySet()) {
        String name = (String) scenarioName;
        String value = properties.getProperty(name);
        batchTest.addBatchTestScenario(name + "," + value);
    }
}

From source file:net.padaf.preflight.TestIsartorValidationFromClasspath.java

@Parameters
public static Collection<Object[]> initializeParameters() throws Exception {
    // load expected errors
    InputStream expected = IsartorTargetFileInformation.class.getResourceAsStream("/expected_errors.txt");
    Properties props = new Properties();
    props.load(expected);
    IOUtils.closeQuietly(expected);//from   w  w  w .jav a 2  s  .  c  o m
    // prepare config
    List<Object[]> data = new ArrayList<Object[]>();
    InputStream is = Class.class.getResourceAsStream("/Isartor testsuite.list");
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    String line = reader.readLine();
    while (line != null) {
        String fn = new File(line).getName();
        String error = new StringTokenizer(props.getProperty(fn), "//").nextToken().trim();
        Object[] tmp = new Object[] { "/" + line, error };
        data.add(tmp);
        line = reader.readLine();
    }
    return data;
}

From source file:Main.java

/** Loads properties into a file.
 * <P>This assumes the file was written with the
 * <code>Properties.store()</code> method.
 *//*from  www.  ja  v  a  2s  . co  m*/
public static void load(Properties p, URL url) throws IOException {
    InputStream in = null;
    try {
        in = url.openStream();
        p.load(in);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (Throwable t) {
            }
        }
    }
}

From source file:com.u2apple.tool.service.IdentifyAnalyticsService.java

private static Map loadModels() {
    Map<String, String> map = new HashMap<>();
    Properties props = new Properties();
    try {//w w  w . j a va2s .c  om
        props.load(IdentifyAnalyticsService.class.getResourceAsStream(Constants.MODELS));
        props.forEach((Object key, Object value) -> {
            String productId = (String) key;
            String model = AndroidDeviceUtils.formatModel((String) value);
            if (model.contains(",")) {
                String[] models = model.split(",");
                for (String m : models) {
                    map.put(m.trim(), productId);
                }
            } else {
                map.put(model, productId);
            }
        });
    } catch (IOException ex) {
        Logger.getLogger(IdentifyAnalyticsService.class.getName()).log(Level.SEVERE, null, ex);
    }
    return map;
}

From source file:com.chiralbehaviors.seurat.service.DemoScenarioTest.java

@BeforeClass
public static void createEMF() throws IOException, SQLException {
    if (emf == null) {
        InputStream is = ModelTest.class.getResourceAsStream("/jpa.properties");
        assertNotNull("jpa properties missing", is);
        Properties properties = new Properties();
        properties.load(is);
        System.out.println(//from  w w  w. j  av  a 2  s . c  o  m
                String.format("Database URL: %s", properties.getProperty("javax.persistence.jdbc.url")));
        emf = Persistence.createEntityManagerFactory(WellKnownObject.CORE, properties);
    }
}

From source file:net.itransformers.bgpPeeringMap.BgpPeeringMap.java

private static Map<String, String> loadProperties(File file) throws IOException {
    Properties props = new Properties();
    props.load(new FileInputStream(file));
    HashMap<String, String> settings = new HashMap<String, String>();
    for (Object key : props.keySet()) {
        settings.put((String) key, (String) props.get(key));
    }//from   www .j  a  va 2s  . c  o  m
    return settings;
}

From source file:com.bt.aloha.batchtest.WeekendBatchTest.java

protected static void configure(BatchTest batchTest) throws Exception {
    Properties properties = new Properties();
    InputStream is = new FileInputStream(CONFIG_FILE);
    properties.load(is);
    is.close();//  w  ww. j av  a2 s. c o m
    sleepTime = Integer.parseInt(properties.getProperty("sleepTime", Integer.toString(defaultSleepTime)));
    batchTest.setAudioFileUri(properties.getProperty("audioFileUri", "/provisioned/behave.wav"));
    stop = Boolean.parseBoolean(properties.getProperty("stop", "false"));
    batchTest.setNumberOfRuns(Integer.parseInt(properties.getProperty("numberOfRuns", "1000")));
    int concurrentStarts = Integer.parseInt(properties.getProperty("numberOfConcurrentStarts", "4"));
    batchTest.setNumberOfConcurrentStarts(concurrentStarts);
    if (executorService == null)
        executorService = Executors.newFixedThreadPool(concurrentStarts);
    batchTest.setExecutorService(executorService);
    batchTest.setMaximumScenarioCompletionWaitTimeSeconds(
            Integer.parseInt(properties.getProperty("maximumScenarioCompletionWaitTimeSeconds", "60")));
    addBatchScenarios(batchTest);
}

From source file:com.jkoolcloud.tnt4j.streams.custom.kafka.interceptors.InterceptorsTest.java

private static Consumer<String, String> initConsumer() throws Exception {
    Properties props = new Properties();
    props.load(new FileReader(System.getProperty("consumer.config"))); // NON-NLS
    topicName = props.getProperty("test.app.topic.name", "tnt4j_streams_kafka_intercept_test_page_visits"); // NON-NLS
    props.remove("test.app.topic.name");

    Consumer<String, String> consumer = new KafkaConsumer<>(props);
    consumer.subscribe(Collections.singletonList(topicName));

    return consumer;
}

From source file:fi.laverca.examples.util.ExampleConf.java

/**
 * Get the properties object of this configuration
 * @param confPath Configuration file path
 * @return Java Properties containing the configuration
 *//*from  w  w w .ja v a  2  s. co  m*/
public static Properties getProperties(final String confPath) {
    File f = new File(confPath);
    Properties properties = new Properties();
    FileInputStream is;
    try {
        is = new FileInputStream(f);
        properties.load(is);
        is.close();
    } catch (Exception e) {
        log.fatal("Could not load properties");
    }
    return properties;
}