List of usage examples for java.util Properties load
public synchronized void load(InputStream inStream) throws IOException
From source file:io.apiman.servers.gateway_h2.Starter.java
/** * Loads properties from a file and puts them into system properties. *//* ww w.j a va 2 s . c o m*/ @SuppressWarnings({ "unchecked" }) protected static void loadProperties() { URL configUrl = Starter.class.getClassLoader().getResource("gateway_h2-apiman.properties"); if (configUrl == null) { throw new RuntimeException( "Failed to find properties file (see README.md): gateway_h2-apiman.properties"); } InputStream is = null; try { is = configUrl.openStream(); Properties props = new Properties(); props.load(is); Enumeration<String> names = (Enumeration<String>) props.propertyNames(); while (names.hasMoreElements()) { String name = names.nextElement(); String value = props.getProperty(name); System.setProperty(name, value); } } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(is); } }
From source file:net.ontopia.utils.PropertyUtils.java
/** * INTERNAL; Reads properties from a file. *//*from w w w . j av a2 s. c om*/ public static Properties loadProperties(File propfile) throws IOException { if (!propfile.exists()) throw new OntopiaRuntimeException("Property file '" + propfile.getPath() + "' does not exist."); // Load properties from file Properties properties = new Properties(); properties.load(new FileInputStream(propfile)); return properties; }
From source file:com.aionemu.commons.utils.PropertiesUtils.java
/** * Loads properties by given file/* ww w. j a v a 2 s . c o m*/ * * @param file filename * @return loaded properties * @throws java.io.IOException if can't load file */ public static Properties load(File file) throws IOException { FileInputStream fis = new FileInputStream(file); Properties p = new Properties(); p.load(fis); fis.close(); return p; }
From source file:com.thoughtworks.go.agent.bootstrapper.osx.AgentMacWindow.java
private static Properties loadPrefs() throws IOException { FileInputStream stream = null; try {//from w w w . ja va2s. c om stream = new FileInputStream(PREFS_FILE); Properties myProps = defaultProperties(); myProps.load(stream); LOG.info("Loaded preferences from " + PREFS_FILE); return myProps; } catch (Exception e) { LOG.error("File not found for " + PREFS_FILE, e); } finally { closeQuietly(stream); } return new Properties(); }
From source file:me.ineson.testing.utils.GradleConfig.java
private static synchronized String readGradleConfig(String key) { if (GRADLE_PROPERTIES == null) { File filename = new File(SystemUtils.getUserHome(), ".gradle/gradle.properties"); if (!filename.exists() || !filename.isFile() || !filename.canRead()) { throw new IllegalStateException("Failed to access gradle configuration: " + filename.getAbsolutePath() + ", exists " + filename.exists() + ", isFile " + filename.isFile() + ", canRead " + filename.canRead()); }/*from w w w . ja v a 2 s .c o m*/ Properties properties = new Properties(); try { properties.load(new FileInputStream(filename)); } catch (FileNotFoundException e) { throw new IllegalStateException( "Failed to access gradle configuration: " + filename.getAbsolutePath(), e); } catch (IOException e) { throw new IllegalStateException( "Failed to access gradle configuration: " + filename.getAbsolutePath(), e); } GRADLE_PROPERTIES = properties; } String fullKey = "systemProp." + key; String value = GRADLE_PROPERTIES.getProperty(fullKey); if (value != null) { System.setProperty(key, value); } return value; }
From source file:at.ac.tuwien.dsg.comot.m.adapter.Main.java
private static String getServiceInstanceId() { String serviceId = null;//from w ww .j a va 2s . com try (InputStream input = new FileInputStream(PROPERTIES_FILE)) { Properties prop = new Properties(); prop.load(input); serviceId = prop.getProperty(SERVICE_INSTANCE_AS_PROPERTY); LOG.info("service={}", serviceId); } catch (IOException e) { LOG.error(" {}", e); } if (serviceId == null) { LOG.error("there is no property '{}'", SERVICE_INSTANCE_AS_PROPERTY); throw new IllegalArgumentException("there is no property " + SERVICE_INSTANCE_AS_PROPERTY); } return serviceId; }
From source file:com.htmlhifive.tools.jslint.engine.option.CheckOptionFileWrapperFactory.java
/** * ???.//w w w . j ava 2 s . c o m * * @param file ?. * @param extension ?. * @return ?. * @throws CoreException ?. */ private static CheckOptionFileWrapper createCheckOptionFileWrapper(IFile file, String extension) throws CoreException { try { if (!file.exists()) { JaxbUtil.saveJsCheckOption(new JsCheckOption(), file); } if (StringUtils.endsWith(extension, "xml")) { return new CheckOptionXmlWrapper(file); } else if (StringUtils.endsWith(extension, "properties")) { Properties prop = new Properties(); prop.load(file.getContents()); // TODO ?. return new CheckOptionPropertyWrapper(prop); } } catch (IOException e) { throw new RuntimeException(e); } catch (JAXBException e) { throw new CoreException( new Status(IStatus.ERROR, JSLintPlugin.PLUGIN_ID, Messages.EM0008.getText(), e)); } return null; }
From source file:com.madgag.agit.GitTestUtils.java
public static String gitServerHostAddress() throws IOException, FileNotFoundException, UnknownHostException { File bang = new File(Environment.getExternalStorageDirectory(), "agit-integration-test.properties"); Properties properties = new Properties(); if (bang.exists()) { properties.load(new FileReader(bang)); }/*from w ww .j a va2 s.c o m*/ String hostAddress = properties.getProperty("gitserver.host.address", "10.0.2.2"); InetAddress address = InetAddress.getByName(hostAddress); assertThat("Test gitserver host " + hostAddress + " is reachable", address.isReachable(1000), is(true)); return hostAddress; }
From source file:io.silverware.microservices.Boot.java
/** * Load custom properties from file on a classpath. * * @return Properties from silverware.properties when present on a classpath. *//*from w w w.ja v a2 s .c o m*/ private static Properties loadProperties() { Properties props = new Properties(); try { props.load(Boot.class.getResourceAsStream("silverware.properties")); } catch (NullPointerException | IOException ioe) { log.info("No configuration property file available. Using default values."); } return props; }
From source file:com.joliciel.talismane.utils.StringUtils.java
/** * Get a map of strings from a properties file. *//*w ww.j ava 2 s . com*/ public static Map<String, String> getArgMap(File propsFile) { try { FileInputStream propsInputStream = new FileInputStream(propsFile); Properties props = new Properties(); props.load(propsInputStream); return getArgMap(props); } catch (IOException e) { LogUtils.logError(LOG, e); throw new RuntimeException(e); } }