List of usage examples for java.util Properties load
public synchronized void load(InputStream inStream) throws IOException
From source file:com.leosys.core.utils.HttpServiceImpl.java
public static String getZiku(String domin) { Properties p = new Properties(); String urls = getXmlPath();/*w ww. ja va 2 s.c om*/ try { p.load(new FileInputStream(urls)); } catch (Exception e) { e.printStackTrace(); } String subUrl = p.getProperty("path"); String restUrl = subUrl + "model=myservice&action=getwebsiteziku&domain=" + domin + "&pagesize=1000"; StringBuffer strBuf; strBuf = new StringBuffer(); try { URL url = new URL(restUrl); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));//? String line = null; while ((line = reader.readLine()) != null) strBuf.append(line + " "); reader.close(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } System.out.println(strBuf.toString()); return strBuf.toString(); }
From source file:com.leosys.core.utils.HttpServiceImpl.java
public static String getMyitem(String letter, Integer page) { Properties p = new Properties(); String urls = getXmlPath();/*from www. jav a 2s . c o m*/ try { p.load(new FileInputStream(urls)); } catch (Exception e) { e.printStackTrace(); } String subUrl = p.getProperty("path"); String restUrl = subUrl + "model=myservice&action=getwebdomainsitebypage&page=" + page + "&pagesize=10"; if (StringUtils.isNotEmpty(letter)) { restUrl += "&letter=" + letter; } StringBuffer strBuf; strBuf = new StringBuffer(); try { URL url = new URL(restUrl); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));//? String line = null; while ((line = reader.readLine()) != null) strBuf.append(line + " "); reader.close(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } System.out.println(strBuf.toString()); return strBuf.toString(); }
From source file:info.bitoo.Main.java
static Properties readConfiguration(CommandLine cmd) { /*/*from w w w .ja v a2 s . c om*/ * Read configuration file */ String configFilename = defaultConfigFilename; if (cmd.hasOption("c")) { configFilename = cmd.getOptionValue("c"); } Properties props = new Properties(); try { FileInputStream fis = new FileInputStream(configFilename); props.load(fis); fis.close(); PropertyConfigurator.configure(props); logger.debug("Log4j initialized"); } catch (FileNotFoundException e) { System.out.println("Configuration file not found: [" + configFilename + "]"); e.printStackTrace(); } catch (IOException e) { System.out.println("Bad configuration file: [" + configFilename + "]"); e.printStackTrace(); } return props; }
From source file:ClassUtils.java
/** * Load a properties file from the classpath. * /*from w ww.ja v a2 s. c om*/ * @param name Name of the properties file * @throws IOException If the properties file could not be loaded */ public static Properties getResourceAsProperties(String name) throws IOException { ClassLoader cl = getClassLoader(); InputStream is = null; is = cl.getResourceAsStream(name); if (is == null) { throw new IOException("Unable to load " + " " + name); } Properties props = new Properties(); props.load(is); return props; }
From source file:com.symantec.cpe.config.ConfigHelper.java
/** * Load config from file: implement the function loadConfig, blind to users. *//*from w ww. j a va 2s .c o m*/ private static Config loadConfigFromFile(String propertiesFileName) throws IOException { Config conf = new Config(); try { // Load configs from properties file LOG.debug("Loading properties from " + propertiesFileName); InputStream fileInputStream = new FileInputStream(propertiesFileName); Properties properties = new Properties(); try { properties.load(fileInputStream); } finally { fileInputStream.close(); } for (@SuppressWarnings("rawtypes") Map.Entry me : properties.entrySet()) { try { // Check every property and covert to appropriate data type before // adding it to storm config. If no data type defined keep it as string if (keyTypeMap.containsKey(me.getKey().toString())) { if (Number.class.equals(keyTypeMap.get(me.getKey().toString()))) { conf.put((String) me.getKey(), Long.valueOf(((String) me.getValue()).trim())); } else if (Map.class.equals(keyTypeMap.get(me.getKey().toString()))) { if (me.getValue() != null) { Map<String, Object> map = new HashMap<String, Object>(); String kvPairs[] = StringUtils.split(me.getValue().toString(), properties.getProperty("map.kv.pair.separator", ",")); for (String kvPair : kvPairs) { String kv[] = StringUtils.split(kvPair, properties.getProperty("map.kv.separator", "=")); map.put((String) kv[0], kv[1].trim()); } conf.put((String) me.getKey(), map); } } else if (Boolean.class.equals(keyTypeMap.get((String) me.getKey()))) { conf.put((String) me.getKey(), Boolean.valueOf(((String) me.getValue()).trim())); } } else { conf.put(me.getKey().toString(), me.getValue()); } } catch (NumberFormatException nfe) { LOG.error("Failed while loading properties from file " + propertiesFileName + ". The value '" + me.getValue() + "' for property " + me.getKey() + " is expected to be numeric", nfe); throw nfe; } } } catch (IOException ioe) { LOG.error("Failed while loading properties from file " + propertiesFileName, ioe); throw ioe; } return conf; }
From source file:io.silverware.microservices.Boot.java
private static Properties loadProperties(final File propertiesFile) { Properties props = new Properties(); try (FileInputStream fis = new FileInputStream(propertiesFile)) { props.load(fis); } catch (IOException ioe) { log.warn("Cannot read configuration property file %s.", propertiesFile.getAbsolutePath()); }//w ww . j a v a 2 s . com return props; }
From source file:io.cloudslang.lang.cli.SlangBootstrap.java
private static void loadUserProperties() throws IOException { String appHome = System.getProperty("app.home"); String propertyFilePath = appHome + File.separator + USER_CONFIG_FILEPATH; File propertyFile = new File(propertyFilePath); Properties rawProperties = new Properties(); if (propertyFile.isFile()) { try (InputStream propertiesStream = new FileInputStream(propertyFilePath)) { rawProperties.load(propertiesStream); }/*from w w w .ja va 2s .c om*/ } Set<Map.Entry<Object, Object>> propertyEntries = rawProperties.entrySet(); for (Map.Entry<Object, Object> property : propertyEntries) { String key = (String) property.getKey(); String value = (String) property.getValue(); value = substitutePropertyReferences(value); System.setProperty(key, value); } }
From source file:com.bmwcarit.barefoot.roadmap.Loader.java
/** * Loads {@link RoadMap} object from database (or file buffer, if set to true) using database * connection parameters provided with the properties. For details on properties, see * {@link Loader#roadmap(Properties, boolean)}. * * @param propertiesPath Path to properties file. * @param buffer Indicates if map shall be read from file buffer and written to file buffer. * @return {@link RoadMap} read from source. (Note: It is not yet constructed!) * @throws SourceException thrown if reading properties, road types or road map data fails. * @throws IOException thrown if opening properties file fails. *//*from www . j a v a 2 s . c om*/ public static RoadMap roadmap(String propertiesPath, boolean buffer) throws SourceException, IOException { InputStream is = new FileInputStream(propertiesPath); Properties props = new Properties(); props.load(is); is.close(); return roadmap(props, buffer); }
From source file:edu.umn.msi.tropix.proteomics.parameters.ParameterUtils.java
/** * Reads properties input a map and calls {@link #setParametersFromMap(Map, Object)}. * //from ww w.j a v a2 s . c om * @param inputStream * Stream to read Java properties from. * @param parameterObject * Object to set parameters on. See {@link #setParametersFromMap(Map, Object)}. * @throws IOException */ public static void setParametersFromProperties(final InputStream inputStream, final Object parameterObject) { final Properties props = new Properties(); try { props.load(inputStream); } catch (final IOException e) { throw new IORuntimeException(e); } setParametersFromMap(props, parameterObject); }
From source file:gov.pnnl.cloud.KinesisApplication.java
/** * @param propertiesFile/* w w w .ja va2 s .co m*/ * @throws IOException Thrown when we run into issues reading properties */ private static void loadProperties(String propertiesFile) throws IOException { FileInputStream inputStream = new FileInputStream(propertiesFile); Properties properties = new Properties(); try { properties.load(inputStream); } finally { inputStream.close(); } String appNameOverride = properties.getProperty(ConfigKeys.APPLICATION_NAME_KEY); if (appNameOverride != null) { applicationName = appNameOverride; } LOG.info("Using application name " + applicationName); String streamNameOverride = properties.getProperty(ConfigKeys.STREAM_NAME_KEY); if (streamNameOverride != null) { streamName = streamNameOverride; } LOG.info("Using stream name " + streamName); String kinesisEndpointOverride = properties.getProperty(ConfigKeys.KINESIS_ENDPOINT_KEY); if (kinesisEndpointOverride != null) { kinesisEndpoint = kinesisEndpointOverride; } LOG.info("Using Kinesis endpoint " + kinesisEndpoint); String initialPositionOverride = properties.getProperty(ConfigKeys.INITIAL_POSITION_IN_STREAM_KEY); if (initialPositionOverride != null) { initialPositionInStream = InitialPositionInStream.valueOf(initialPositionOverride); } LOG.info("Using initial position " + initialPositionInStream.toString() + " (if a checkpoint is not found)."); String kafkaBrokerListProperty = properties.getProperty(ConfigKeys.KAFKA_BROKER_LIST); if (kafkaBrokerListProperty == null) { throw new IOException("kafkaBrokerList cannot be null"); } kafkaBrokerList = kafkaBrokerListProperty; LOG.info("Using Kafka broker list " + kafkaBrokerList); }