Java Code Examples for java.util.Properties.load()

The following are Jave code examples for showing how to use load() of the java.util.Properties class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: convertigo-eclipse   File: ConfigManager.java   Source Code and License Vote up 6 votes
public boolean init() {
 	props = new Properties();
 	
 	if (fileName == null)
 		return false;
     
 	try {
         InputStream inStream = new FileInputStream(fileName);
         props.load(inStream);
         /*Iterator iter = props.keySet().iterator();
         logger.debug("Properties:");
         while (iter.hasNext()) {
             String key = (String)iter.next();
             logger.debug(key + " -> " + props.get(key));
         }*/
         return true;
     }
     catch (IOException e) {
ConvertigoPlugin.logException(e, "Unexpected exception");
         throw new RuntimeException("Couldn't read properties");
     }
 }
 
Example 2
Project: fresco_floodlight   File: FloodlightModuleLoader.java   Source Code and License Vote up 6 votes
private void mergeProperties(InputStream is,
                             File confFile,
                             Collection<String> configMods,
                             Properties prop)
                                     throws FloodlightModuleException {
    try {
        Properties fprop = new Properties();
        if (is != null) {
            fprop.load(is);
        } else {
            try (FileInputStream fis = new FileInputStream(confFile)) {
                fprop.load(fis);
            }
        }
        String moduleList = fprop.getProperty(FLOODLIGHT_MODULES_KEY);
        if (moduleList != null) {
            moduleList = moduleList.replaceAll("\\s", "");
            configMods.addAll(Arrays.asList(moduleList.split(",")));
        }
        fprop.remove(FLOODLIGHT_MODULES_KEY);

        prop.putAll(fprop);
    } catch (IOException e) {
        throw new FloodlightModuleException(e);
    }
}
 
Example 3
Project: incubator-netbeans   File: ProjectConfigurations.java   Source Code and License Vote up 6 votes
@NonNull
private Map<String,Configuration> calculateConfigs() {
    final Map<String,Configuration> cfgs = new HashMap<>();
    if (configDir != null) {
        for (FileObject kid : configDir.getChildren()) {
            if (!kid.hasExt("properties")) {    //NOI18N
                continue;
            }
            try {
                try (InputStream is = kid.getInputStream()) {
                    final Properties props = new Properties();
                    props.load(is);
                    final String name = kid.getName();
                    final String label = props.getProperty("$label"); // NOI18N
                    cfgs.put(name, new Configuration(name, label != null ? label : name));
                }
            } catch (IOException x) {
                LOGGER.log(Level.INFO, null, x);
            }
        }
    }
    configs = cfgs;
    LOGGER.log(Level.FINEST, "Calculated configurations: {0}", cfgs);
    return cfgs;
}
 
Example 4
Project: openjdk-jdk10   File: MBeanServerFileAccessController.java   Source Code and License Vote up 6 votes
private static Properties propertiesFromFile(String fname)
    throws IOException {
    FileInputStream fin = new FileInputStream(fname);
    try {
        Properties p = new Properties();
        p.load(fin);
        return p;
    } finally {
        fin.close();
    }
}
 
Example 5
Project: incubator-netbeans   File: TaskCache.java   Source Code and License Vote up 6 votes
@NonNull
private static Properties loadRelocation(
        @NonNull final File cacheRoot) {
    final Properties result = new Properties();
    final  File relocationFile = new File (cacheRoot, RELOCATION_FILE);
    if (relocationFile.canRead()) {
        try {
            final FileInputStream in = new FileInputStream(relocationFile);
            try {
                result.load(in);
           } finally {
                in.close();
           }
        } catch (IOException ioe) {
            Exceptions.printStackTrace(ioe);
        }
    }
    return result;
}
 
Example 6
Project: Cognizant-Intelligent-Test-Scripter   File: SeleniumServer.java   Source Code and License Vote up 5 votes
private Properties loadProperties(String location) {
    Properties prop = new Properties();
    if (new File(location).exists()) {
        try (FileInputStream inputStream = new FileInputStream(location)) {
            prop.load(inputStream);
        } catch (IOException ex) {
            Logger.getLogger(SeleniumServer.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    return prop;
}
 
Example 7
Project: openjdk-jdk10   File: MFontConfiguration.java   Source Code and License Vote up 5 votes
/**
 * Sets the OS name and version from environment information.
 */
protected void setOsNameAndVersion(){
    super.setOsNameAndVersion();

    if (osName.equals("SunOS")) {
        //don't care os name on Solaris
        osName = null;
    } else if (osName.equals("Linux")) {
        try {
            File f;
            if ((f = new File("/etc/fedora-release")).canRead()) {
                osName = "Fedora";
                osVersion = getVersionString(f);
            } else if ((f = new File("/etc/redhat-release")).canRead()) {
                osName = "RedHat";
                osVersion = getVersionString(f);
            } else if ((f = new File("/etc/turbolinux-release")).canRead()) {
                osName = "Turbo";
                osVersion = getVersionString(f);
            } else if ((f = new File("/etc/SuSE-release")).canRead()) {
                osName = "SuSE";
                osVersion = getVersionString(f);
            } else if ((f = new File("/etc/lsb-release")).canRead()) {
                /* Ubuntu and (perhaps others) use only lsb-release.
                 * Syntax and encoding is compatible with java properties.
                 * For Ubuntu the ID is "Ubuntu".
                 */
                Properties props = new Properties();
                props.load(new FileInputStream(f));
                osName = props.getProperty("DISTRIB_ID");
                osVersion =  props.getProperty("DISTRIB_RELEASE");
            }
        } catch (Exception e) {
        }
    }
    return;
}
 
Example 8
Project: secure-tomcat-datasourcefactory   File: PropertyParser.java   Source Code and License Vote up 5 votes
public static Properties parseProperties(String propertyString) {
	Properties properties = new Properties();
	try {
		Reader propertyReader = new StringReader(propertyString.replaceAll(";", "\n"));
		properties.load(propertyReader);
	} catch (IOException e) {
		// Can't happen with StringReader
	}
	return properties;
}
 
Example 9
Project: app-service-java-manage-functions   File: Utils.java   Source Code and License Vote up 5 votes
/**
 * Retrieve the secondary service principal client ID.
 * @param envSecondaryServicePrincipal an Azure Container Registry
 * @return a service principal client ID
 * @throws Exception exception
 */
public static String getSecondaryServicePrincipalClientID(String envSecondaryServicePrincipal) throws Exception {
    Properties authSettings = new Properties();
    FileInputStream credentialsFileStream = new FileInputStream(new File(envSecondaryServicePrincipal));
    authSettings.load(credentialsFileStream);
    credentialsFileStream.close();

    return authSettings.getProperty("client");
}
 
Example 10
Project: SigFW   File: DiameterServer.java   Source Code and License Vote up 5 votes
private static void configLog4j() {
	InputStream inStreamLog4j = DiameterServer.class.getClassLoader().getResourceAsStream("log4j.properties");
	Properties propertiesLog4j = new Properties();
	try {
		propertiesLog4j.load(inStreamLog4j);
		PropertyConfigurator.configure(propertiesLog4j);
	} catch (Exception e) {
		e.printStackTrace();
	}

	log.debug("log4j configured");

}
 
Example 11
Project: picocli   File: VersionProviderDemo1.java   Source Code and License Vote up 5 votes
public String[] getVersion() throws Exception {
    URL url = getClass().getResource("/version.txt");
    if (url == null) {
        return new String[] {"No version.txt file found in the classpath. Is examples.jar in the classpath?"};
    }
    Properties properties = new Properties();
    properties.load(url.openStream());
    return new String[] {
            properties.getProperty("Application-name") + " version \"" + properties.getProperty("Version") + "\"",
            "Built: " + properties.getProperty("Buildtime"),
    };
}
 
Example 12
Project: agroal   File: AgroalPropertiesReader.java   Source Code and License Vote up 5 votes
public AgroalPropertiesReader readProperties(File file) throws IOException {
    try ( InputStream inputStream = new FileInputStream( file ) ) {
        Properties properties = new Properties();
        properties.load( inputStream );
        return readProperties( properties );
    }
}
 
Example 13
Project: Reer   File: WrapperExecutor.java   Source Code and License Vote up 5 votes
private static void loadProperties(File propertiesFile, Properties properties) throws IOException {
    InputStream inStream = new FileInputStream(propertiesFile);
    try {
        properties.load(inStream);
    } finally {
        inStream.close();
    }
}
 
Example 14
Project: lams   File: SchemaExportTask.java   Source Code and License Vote up 5 votes
private SchemaExport getSchemaExport(Configuration cfg) throws HibernateException, IOException {
	Properties properties = new Properties();
	properties.putAll( cfg.getProperties() );
	if (propertiesFile == null) {
		properties.putAll( getProject().getProperties() );
	}
	else {
		properties.load( new FileInputStream(propertiesFile) );
	}
	cfg.setProperties(properties);
	return new SchemaExport(cfg)
			.setHaltOnError(haltOnError)
			.setOutputFile( outputFile.getPath() )
			.setDelimiter(delimiter);
}
 
Example 15
Project: springboot-training   File: ConfigItem.java   Source Code and License Vote up 5 votes
/**
 * 取默认的配置文件
 */
ConfigItem(String file) {
	try (InputStream is = ConfigUtil.class.getResourceAsStream(file)) {
		Properties p = new Properties();
		p.load(is);
		this.pro = p;
	} catch (IOException e) {
		throw new ZhhrException("加载配置信息出错:" + e.getMessage());
	}
}
 
Example 16
Project: n4js   File: WorkspaceSetupTest.java   Source Code and License Vote up 5 votes
/** */
@Test
public void testLineDelimiter() throws IOException {
	Assume.assumeTrue(runtimePrefs.exists());
	try (InputStream in = new FileInputStream(runtimePrefs)) {
		Properties props = new Properties();
		props.load(in);
		Assert.assertEquals("\n", props.getProperty("line.separator"));
	}
}
 
Example 17
Project: webdriver-junit5-archetype   File: SuiteConfiguration.java   Source Code and License Vote up 4 votes
public SuiteConfiguration(String fromResource) throws IOException {
  properties = new Properties();
  properties.load(SuiteConfiguration.class.getResourceAsStream(fromResource));
}
 
Example 18
Project: https-github.com-apache-zookeeper   File: QuorumPeer.java   Source Code and License Vote up 4 votes
public QuorumVerifier configFromString(String s) throws IOException, ConfigException{
    Properties props = new Properties();        
    props.load(new StringReader(s));
    return QuorumPeerConfig.parseDynamicConfig(props, electionType, false, false);
}
 
Example 19
Project: uavstack   File: AbstractIT.java   Source Code and License Vote up 4 votes
/**
 * loadMOFConfig
 */
protected void loadMOFConfig() {

    // load uav.properties
    String uavProFilePath = this.uavMofRoot + "/com.creditease.uav/uav.properties";
    File configFile = new File(uavProFilePath);

    if (configFile.exists()) {
        try {
            Properties config = new Properties();

            config.load(new FileInputStream(configFile));

            Set<Entry<Object, Object>> cfgSet = config.entrySet();

            if (!cfgSet.isEmpty()) {
                for (Entry<Object, Object> entry : cfgSet) {
                    String key = (String) entry.getKey();
                    String value = (String) entry.getValue();

                    /**
                     * NOTE: if uavmof is inside Container, make sure we use the 1st netcard
                     */
                    if (null != System.getenv("IS_ULTRON") && true == Boolean.valueOf(System.getenv("IS_ULTRON"))) {
                        if (key.equals("NetCardIndex")) {
                            value = "0";
                        }
                    }

                    if (System.getProperty(key) == null) {
                        System.setProperty(key, value);
                    }

                }
            }

        }
        catch (Exception e) {
            // ignore
        }
    }

}
 
Example 20
Project: enmasse-workshop   File: HeatingDevice.java   Source Code and License Vote up 4 votes
public static void main(String[] args) throws IOException {

        if (args.length < 1) {
            System.err.println("Missing config file parameter");
            System.exit(1);
        }

        String configFile = args[0];

        HeatingDevice heatingDevice = new HeatingDevice();

        InputStream input = new FileInputStream(configFile);
        Properties config = new Properties();
        config.load(input);

        String controlAddress = String.format("%s/%s", config.getProperty(DeviceConfig.CONTROL_PREFIX), config.getProperty(DeviceConfig.DEVICE_ID));
        config.setProperty(DeviceConfig.CONTROL_ADDRESS, controlAddress);

        heatingDevice.init(config);

        heatingDevice.run();
    }