private static String versionString() { try { Properties prop = new Properties(); InputStream in = Main.class.getResourceAsStream("/okcurl-version.properties"); prop.load(in); in.close(); return prop.getProperty("version"); } catch (IOException e) { throw new AssertionError("Could not load okcurl-version.properties."); } }
@Override public Properties convert(String source) { try { Properties props = new Properties(); // Must use the ISO-8859-1 encoding because Properties.load(stream) expects it. props.load(new ByteArrayInputStream(source.getBytes(StandardCharsets.ISO_8859_1))); return props; } catch (Exception ex) { // Should never happen. throw new IllegalArgumentException("Failed to parse [" + source + "] into Properties", ex); } }
Properties properties = new Properties(); try { properties.load(new FileInputStream("path/filename")); } catch (IOException e) { ... }
private static Properties readPropertiesFromFile (File propertiesFile) throws IOException { InputStream stream = null; try { stream = new FileInputStream(propertiesFile); Properties properties = new Properties(); properties.load(stream); return properties; } finally { if (stream != null) { try { stream.close(); } catch (IOException e) { e.printStackTrace(); } } } }
private static void extractTlsConfigFromFile(final File configFile) { if (!(configFile.exists() && configFile.isFile() && configFile.canRead())) { LOGGER.info("Tls config file doesn't exist, skip it"); return; properties = new Properties(); InputStream inputStream = null; try { inputStream = new FileInputStream(configFile); properties.load(inputStream); } catch (IOException ignore) { } finally { if (null != inputStream) { try { inputStream.close(); } catch (IOException ignore) { tlsTestModeEnable = Boolean.parseBoolean(properties.getProperty(TLS_TEST_MODE_ENABLE, String.valueOf(tlsTestModeEnable))); tlsServerNeedClientAuth = properties.getProperty(TLS_SERVER_NEED_CLIENT_AUTH, tlsServerNeedClientAuth); tlsServerKeyPath = properties.getProperty(TLS_SERVER_KEYPATH, tlsServerKeyPath); tlsServerKeyPassword = properties.getProperty(TLS_SERVER_KEYPASSWORD, tlsServerKeyPassword); tlsServerCertPath = properties.getProperty(TLS_SERVER_CERTPATH, tlsServerCertPath);
private static Properties fetchProperties(final String propertiesFilePath) { final Properties properties = new Properties(); InputStream is = null; try { is = FileUtils.openInputStream(new File(propertiesFilePath)); properties.load(is); } catch (Throwable cause) { // cause.printStackTrace(System.err); } finally { IOUtils.closeQuietly(is); } return properties; }
public static Map<String, String> parseProperties(String content) throws IOException { Map<String, String> map = new HashMap<>(); if (StringUtils.isEmpty(content)) { logger.warn("You specified the config centre, but there's not even one single config item in it."); } else { Properties properties = new Properties(); properties.load(new StringReader(content)); properties.stringPropertyNames().forEach( k -> map.put(k, properties.getProperty(k)) ); } return map; }
@Test public void convertPropertiesToString() { Properties foo = new Properties(); foo.setProperty("1", "BAR"); foo.setProperty("2", "BAZ"); String result = conversionService.convert(foo, String.class); assertTrue(result.contains("1=BAR")); assertTrue(result.contains("2=BAZ")); }
public static void write(CandidateComponentsMetadata metadata, OutputStream out) throws IOException { Properties props = new Properties(); metadata.getItems().forEach(m -> props.put(m.getType(), String.join(",", m.getStereotypes()))); props.store(out, ""); }
@Test public void testWithPropertiesFileAndLocalProperties() throws Exception { PropertiesFactoryBean pfb = new PropertiesFactoryBean(); pfb.setLocation(TEST_PROPS); Properties localProps = new Properties(); localProps.setProperty("key2", "value2"); localProps.setProperty("tb.array[0].age", "0"); pfb.setProperties(localProps); pfb.afterPropertiesSet(); Properties props = pfb.getObject(); assertEquals("99", props.getProperty("tb.array[0].age")); assertEquals("value2", props.getProperty("key2")); }
private Properties computeChecksumForContentsOfDirectory(File directory, String destPath) throws IOException { Collection<File> fileStructure = FileUtils.listFiles(directory, null, true); Properties checksumProperties = new Properties(); for (File file : fileStructure) { String filePath = removeStart(file.getAbsolutePath(), directory.getParentFile().getAbsolutePath()); try (FileInputStream inputStream = new FileInputStream(file)) { checksumProperties.setProperty(getEffectiveFileName(destPath, FilenameUtils.separatorsToUnix(filePath)), md5Hex(inputStream)); } } return checksumProperties; }
Properties prop = new Properties(); InputStream in = getClass().getResourceAsStream("foo.properties"); prop.load(in); in.close();
Properties props = new Properties(); while (urls.hasMoreElements()) { URL url = urls.nextElement(); props.load(is); is.close();
private String loadConfigFor(String namespace) { String filename = String.format("mockdata-%s.properties", namespace); final Properties prop = ResourceUtils.readConfigFile(filename, new Properties()); Map<String, String> configurations = Maps.newHashMap(); for (String propertyName : prop.stringPropertyNames()) { configurations.put(propertyName, prop.getProperty(propertyName)); } ApolloConfig apolloConfig = new ApolloConfig("someAppId", "someCluster", namespace, "someReleaseKey"); Map<String, String> mergedConfigurations = mergeOverriddenProperties(namespace, configurations); apolloConfig.setConfigurations(mergedConfigurations); return gson.toJson(apolloConfig); }
Properties properties = new Properties(); InputStream inputStream = new FileInputStream("path/to/file"); try { Reader reader = new InputStreamReader(inputStream, "UTF-8"); try { properties.load(reader); } finally { reader.close(); } } finally { inputStream.close(); }
public static Map<String, String> loadProperties(File file) throws IOException { Properties properties = new Properties(); try (InputStream in = new FileInputStream(file)) { properties.load(in); } return fromProperties(properties); } }
private static String computeVersion() { Properties props = new Properties(); try { InputStream is = CLI.class.getResourceAsStream("/jenkins/cli/jenkins-cli-version.properties"); if(is!=null) { try { props.load(is); } finally { is.close(); } } } catch (IOException e) { e.printStackTrace(); // if the version properties is missing, that's OK. } return props.getProperty("version","?"); }
public static Map<String, String> parseProperties(String content) throws IOException { Map<String, String> map = new HashMap<>(); if (StringUtils.isEmpty(content)) { logger.warn("You specified the config centre, but there's not even one single config item in it."); } else { Properties properties = new Properties(); properties.load(new StringReader(content)); properties.stringPropertyNames().forEach( k -> map.put(k, properties.getProperty(k)) ); } return map; }
@Test public void testGenericMapFromProperties() { GenericBean<?> gb = new GenericBean<>(); BeanWrapper bw = new BeanWrapperImpl(gb); Properties input = new Properties(); input.setProperty("4", "5"); input.setProperty("6", "7"); bw.setPropertyValue("shortMap", input); assertEquals(new Integer(5), gb.getShortMap().get(new Short("4"))); assertEquals(new Integer(7), gb.getShortMap().get(new Short("6"))); }
private static Properties createProperties(String key, String stereotypes) { Properties properties = new Properties(); properties.put(key, String.join(",", stereotypes)); return properties; }