java.util.Properties.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(239)

本文整理了Java中java.util.Properties.<init>()方法的一些代码示例,展示了Properties.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Properties.<init>()方法的具体详情如下:
包路径:java.util.Properties
类名称:Properties
方法名:<init>

Properties.<init>介绍

[英]Constructs a new Properties object.
[中]构造一个新的属性对象。

代码示例

代码示例来源:origin: square/okhttp

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.");
 }
}

代码示例来源:origin: spring-projects/spring-framework

@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);
  }
}

代码示例来源:origin: stackoverflow.com

Properties properties = new Properties();
try {
 properties.load(new FileInputStream("path/filename"));
} catch (IOException e) {
 ...
}

代码示例来源:origin: libgdx/libgdx

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();
      }
    }
  }
}

代码示例来源:origin: apache/rocketmq

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);

代码示例来源:origin: alibaba/jvm-sandbox

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;
}

代码示例来源:origin: apache/incubator-dubbo

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;
}

代码示例来源:origin: spring-projects/spring-framework

@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"));
}

代码示例来源:origin: spring-projects/spring-framework

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, "");
}

代码示例来源:origin: spring-projects/spring-framework

@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"));
}

代码示例来源:origin: gocd/gocd

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;
}

代码示例来源:origin: stackoverflow.com

Properties prop = new Properties();
InputStream in = getClass().getResourceAsStream("foo.properties");
prop.load(in);
in.close();

代码示例来源:origin: spring-projects/spring-framework

Properties props = new Properties();
while (urls.hasMoreElements()) {
  URL url = urls.nextElement();
      props.load(is);
    is.close();

代码示例来源:origin: ctripcorp/apollo

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);
}

代码示例来源:origin: stackoverflow.com

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();
}

代码示例来源:origin: prestodb/presto

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);
  }
}

代码示例来源:origin: jenkinsci/jenkins

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","?");
}

代码示例来源:origin: apache/incubator-dubbo

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;
}

代码示例来源:origin: spring-projects/spring-framework

@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")));
}

代码示例来源:origin: spring-projects/spring-framework

private static Properties createProperties(String key, String stereotypes) {
  Properties properties = new Properties();
  properties.put(key, String.join(",", stereotypes));
  return properties;
}

相关文章

微信公众号

最新文章

更多