List of usage examples for java.util Properties load
public synchronized void load(InputStream inStream) throws IOException
From source file:Main.java
public static String getCurrentProject() { try {// w w w .j a v a2 s. co m String value = ""; Properties properties = new Properties(); FileInputStream inputFile = new FileInputStream(System.getProperty("user.dir") + "/system.properties"); properties.load(inputFile); inputFile.close(); if (properties.containsKey("ProjectPath")) { value = properties.getProperty("ProjectPath"); String resultName = new String(value.getBytes("ISO-8859-1"), "gbk"); return resultName; } else return value; } catch (FileNotFoundException e) { e.printStackTrace(); return ""; } catch (IOException e) { e.printStackTrace(); return ""; } catch (Exception ex) { ex.printStackTrace(); return ""; } }
From source file:org.yamj.api.trakttv.TestLogger.java
/** * Load properties from a file/*from w ww . j a v a2s . com*/ * * @param props * @param propertyFile */ public static void loadProperties(Properties props, File propertyFile) { try (InputStream is = new FileInputStream(propertyFile)) { props.load(is); } catch (Exception ex) { LOG.warn("Failed to load properties file", ex); } }
From source file:de.highbyte_le.weberknecht.Version.java
@SuppressWarnings("nls") public static synchronized Version getAppVersion() { if (null == appVersion) { try {/*from w w w .ja v a2 s. c o m*/ InputStream in = Version.class.getResourceAsStream("version.properties"); //$NON-NLS-1$ if (in != null) { try { Properties p = new Properties(); p.load(in); appVersion = parseProperties(p); } finally { in.close(); } } else { logger.error("getAppVersion() - version.properties not found"); } } catch (IOException e) { logger.error("getAppVersion() - I/O Exception while loading version.properties: " + e.getMessage()); } } return appVersion; }
From source file:de.kurashigegollub.dev.gcatest.Utils.java
/** * Read a configuration value from the properties file * @param string/* w w w .j av a 2s . c o m*/ * @return */ public static String readFromPropertiesAsString(String propertiesFile, String propertyName) throws IOException { InputStream is = Utils.class.getResourceAsStream(propertiesFile.replace('/', File.separatorChar)); if (is == null) { throw new IOException(String.format("Could not find %s", propertiesFile)); } Properties p = new Properties(); p.load(is); return p.getProperty(propertyName); }
From source file:com.hzc.framework.util.PropertiesUtil.java
public static void initExtiact(String extiactConfigPath) { Properties p1 = new Properties(); InputStream is = null;/*from w w w. j a va2s.c om*/ try { is = new FileInputStream(new File(extiactConfigPath)); p1.load(is); p.putAll(p1); } catch (IOException ex) { log.error(ex); } finally { if (is != null) { try { is.close(); } catch (IOException ex) { log.error(ex); } is = null; } } }
From source file:net.ageto.gyrex.impex.persistence.cassandra.ConfigureRepositoryPreferences.java
/** * Read repository Properties from supplied uri and apply them to the * Repository configuration// www.j a va2 s.c o m * * @param url * @param cassandraRepositoryId */ public static void readRepositoryPreferences(final URL url, final String cassandraRepositoryId, IRuntimeContext context) { assignDedicatedCassandraRepositories(context, cassandraRepositoryId); InputStream stream = null; try { stream = url.openStream(); final Properties p = new Properties(); p.load(stream); createRepositoryStore(cassandraRepositoryId, CassandraRepositoryProvider.ID); IRepositoryRegistry repositoryRegistry = ImpexCassandraActivator.getInstance().getRepositoryRegistry(); IRepositoryPreferences repositoryPreferences = repositoryRegistry .getRepositoryDefinition(cassandraRepositoryId).getRepositoryPreferences(); // Cassandra configuration getAndSetProperty(p, ICassandraRepositoryConstants.CONF_CLUSTER_NAME, repositoryPreferences); getAndSetProperty(p, ICassandraRepositoryConstants.CONF_CASSANDRA_HOST, repositoryPreferences); getAndSetProperty(p, ICassandraRepositoryConstants.CONF_KEYSPACE_NAME, repositoryPreferences); getAndSetProperty(p, ICassandraRepositoryConstants.CONF_COLUMN_FAMILY_PROCESSES, repositoryPreferences); getAndSetProperty(p, ICassandraRepositoryConstants.CONF_COLUMN_NAME_PROCESS, repositoryPreferences); getAndSetProperty(p, ICassandraRepositoryConstants.CONF_SUPERCOLUMN_FAMILY_PROCESS_LOGGING, repositoryPreferences); getAndSetProperty(p, ICassandraRepositoryConstants.CONF_COLUMN_NAME_LOGLEVEL, repositoryPreferences); getAndSetProperty(p, ICassandraRepositoryConstants.CONF_COLUMN_NAME_MESSAGE, repositoryPreferences); repositoryPreferences.flush(); // } catch (final FileNotFoundException e) { // throw new IllegalStateException("Cannot read from " + url, e); // } catch (final IOException e) { // throw new IllegalStateException("Cannot read from " + url, e); } catch (final Exception e) { LOG.error("Error while stroring preferences for repository: " + e, e); } finally { IOUtils.closeQuietly(stream); } }
From source file:Main.java
public static String getProperty(String path, String key) { Properties prop = new Properties(); InputStream input = null;//from w ww . j ava 2 s . com String output = ""; try { input = new FileInputStream(path); prop.load(input); output = prop.getProperty(key, ""); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (input != null) { try { input.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return output; }
From source file:de.micromata.genome.logging.DocLogEntries.java
/** * Load./*from ww w . ja va 2 s . c o m*/ * * @param is the is * @return the doc log entries * @throws IOException Signals that an I/O exception has occurred. */ public static DocLogEntries load(InputStream is) throws IOException { Properties props = new Properties(); props.load(is); return load(props); }
From source file:ezbake.deployer.utilities.VersionHelper.java
private static String getVersionFromPomProperties(File artifact) throws IOException { List<JarEntry> pomPropertiesFiles = new ArrayList<>(); String versionNumber = null;/*from w ww . ja va 2 s . c o m*/ try (JarFile jar = new JarFile(artifact)) { JarEntry entry; Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements()) { entry = entries.nextElement(); if (!entry.isDirectory() && entry.getName().endsWith("pom.properties")) { pomPropertiesFiles.add(entry); } } if (pomPropertiesFiles.size() == 1) { Properties pomProperties = new Properties(); pomProperties.load(jar.getInputStream(pomPropertiesFiles.get(0))); versionNumber = pomProperties.getProperty("version", null); } else { logger.debug("Found {} pom.properties files. Cannot use that for version", pomPropertiesFiles.size()); } } return versionNumber; }
From source file:org.unbunt.ella.lang.sql.DBUtils.java
public static DriverManagerDataSource createDataSourceFromProps(String propsFile, String user, String pass, String classOrType) throws DBConnectionFailedException { Properties props = new Properties(); try {/* w w w .ja v a 2s. c o m*/ props.load(new FileInputStream(propsFile)); } catch (IOException e) { throw new DBConnectionFailedException( "Failed to load connection properties: " + propsFile + ": " + e.getMessage(), e); } return createDataSourceFromProps(props, user, pass, classOrType); }