本文整理匯總了Java中java.util.Properties.loadFromXML方法的典型用法代碼示例。如果您正苦於以下問題:Java Properties.loadFromXML方法的具體用法?Java Properties.loadFromXML怎麽用?Java Properties.loadFromXML使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Properties
的用法示例。
在下文中一共展示了Properties.loadFromXML方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: loadPropertiesFromPaths
import java.util.Properties; //導入方法依賴的package包/類
private static Properties loadPropertiesFromPaths(ResourceLoader resourceLoader, List<String> paths) {
Properties configurationProperties = new Properties();
for (String path : paths) {
Resource resource = resourceLoader.getResource(path);
InputStream is = null;
try {
is = resource.getInputStream();
Properties properties = new Properties();
properties.loadFromXML(is);
configurationProperties.putAll(properties);
} catch (IOException ex) {
log.error("Failed to load configuration properties. Resource - " + path, ex);
} finally {
try {
if (is != null) {
is.close();
}
} catch (IOException ioe) {
// ignore
ioe.printStackTrace();
}
}
}
return configurationProperties;
}
示例2: getRuntimeProperties
import java.util.Properties; //導入方法依賴的package包/類
/**
* Return runtime properties of given {@code runtimeProperties}. Looks first, if application is running on a dev machine and returns in this case the
* properties from the resource context. Otherwise a lookup in properties folder in webapps context is fullfilled.
*
* @param runtimeProperties
* @return properties {@link Properties}
* @throws PropertyException
*/
public static Properties getRuntimeProperties(final String runtimeProperties) throws PropertyException {
if (runtimeProperties == null || runtimeProperties.length() == 0) {
throw new PropertyException("path may not be empty or null");
}
final Properties properties = new Properties();
final String fileType = runtimeProperties.substring(runtimeProperties.lastIndexOf(".") + 1, runtimeProperties.length());
final File propFile = readFile(runtimeProperties);
try (FileInputStream fi = new FileInputStream(propFile);) {
if ("xml".equals(fileType)) {
properties.loadFromXML(fi);
} else {
properties.load(fi);
}
} catch (final IOException e) {
System.err.println(ProjectProperty.class.getSimpleName() + " IOException for " + runtimeProperties + " " + e.getMessage());
}
return properties;
}
示例3: readProperties
import java.util.Properties; //導入方法依賴的package包/類
Properties readProperties(CommandLine line, OptionType optionType, ToolRunningContext context) throws IOException {
Properties properties = new Properties();
// Read the parameters file
String filename = line.getOptionValue(optionType.getLongOpt(), null);
if (filename != null) {
try (InputStream inputStream = Files.newInputStream(context.getFileSystem().getPath(filename))) {
if (filename.endsWith(".xml")) {
properties.loadFromXML(inputStream);
} else {
properties.load(inputStream);
}
}
}
// Append parameters from the command line
properties.putAll(line.getOptionProperties(Character.toString(optionType.getShortOpt())));
return properties;
}
示例4: loadMetadataFromFile
import java.util.Properties; //導入方法依賴的package包/類
/**
* @see AbstractMapBasedMetadataLoader#loadMetadataFromFile(java.io.File)
*/
@Override
protected Map<String,Serializable> loadMetadataFromFile(Path metadataFile)
{
Map<String,Serializable> result = null;
try
{
Properties props = new Properties();
props.loadFromXML(new BufferedInputStream(Files.newInputStream(metadataFile)));
result = new HashMap<String,Serializable>((Map)props);
// MNT-18001
removeProtectedProperties(result);
}
catch (final IOException ioe)
{
if (log.isWarnEnabled()) log.warn("Metadata file '" + FileUtils.getFileName(metadataFile) + "' could not be read.", ioe);
}
return(result);
}
示例5: DataStoreAccesor
import java.util.Properties; //導入方法依賴的package包/類
public DataStoreAccesor ( final File basePath, final DataFilePool pool ) throws Exception
{
this.basePath = basePath;
this.pool = pool;
if ( !basePath.isDirectory () )
{
throw new IllegalStateException ( String.format ( "'%s' is not a directory", basePath ) );
}
final Properties p = new Properties ();
p.loadFromXML ( new FileInputStream ( new File ( basePath, "settings.xml" ) ) );
this.time = Long.parseLong ( p.getProperty ( "time" ) );
this.unit = TimeUnit.valueOf ( p.getProperty ( "unit" ) );
this.count = Integer.parseInt ( p.getProperty ( "count" ) );
this.quantizer = new Quantizer ( this.time, this.unit, this.count );
}
示例6: call
import java.util.Properties; //導入方法依賴的package包/類
public Void call() throws IOException {
while (!done) {
// store as XML format
ByteArrayOutputStream out = new ByteArrayOutputStream();
props.storeToXML(out, null, "UTF-8");
// load from XML format
Properties p = new Properties();
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
p.loadFromXML(in);
// check that the properties are as expected
if (!p.equals(props))
throw new RuntimeException("Properties not equal");
}
return null;
}
示例7: load
import java.util.Properties; //導入方法依賴的package包/類
void load(String file) throws IOException {
Properties mainProperties = new Properties();
try (InputStream inputStream = new FileInputStream(file)) {
mainProperties.loadFromXML(inputStream);
}
String defaultConfigFile = mainProperties.getProperty("config.default");
if (defaultConfigFile != null) {
try (InputStream inputStream = new FileInputStream(defaultConfigFile)) {
properties.loadFromXML(inputStream);
}
}
properties.putAll(mainProperties); // override defaults
useEnvironmentVariables = Boolean.parseBoolean(System.getenv("CONFIG_USE_ENVIRONMENT_VARIABLES"))
|| Boolean.parseBoolean(properties.getProperty("config.useEnvironmentVariables"));
}
示例8: getConnectionProperties
import java.util.Properties; //導入方法依賴的package包/類
protected static Properties getConnectionProperties(
BillingAdapter billingAdapter) throws BillingApplicationException {
Properties connectionProperties = new Properties();
if (billingAdapter.getConnectionProperties() != null) {
try (InputStream in = IOUtils.toInputStream(
billingAdapter.getConnectionProperties(),
StandardCharsets.UTF_8.toString());) {
connectionProperties.loadFromXML(in);
} catch (IOException e) {
throw new BillingApplicationException(
"No Connection to Billing Adapter",
new BillingAdapterConnectionException(
"Unable to load Connection properties", e));
}
} else {
throw new BillingApplicationException(
"No Connection to Billing Adapter",
new BillingAdapterConnectionException(
"Connection properties are missing"));
}
return connectionProperties;
}
示例9: loadProperties
import java.util.Properties; //導入方法依賴的package包/類
protected void loadProperties(Properties properties, FileObject storage) throws IOException {
synchronized (this) {
InputStream is = storage.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
try {
properties.loadFromXML(bis);
} finally {
bis.close();
}
}
}
示例10: getFoldersList
import java.util.Properties; //導入方法依賴的package包/類
private Properties getFoldersList() throws FileNotFoundException, IOException{
Properties p = new Properties();
if(Files.exists(new File(PATH).toPath())){
FileInputStream in = new FileInputStream(new File(PATH));
p.loadFromXML(in);
BiConsumer<Object,Object> bi = (x,y) ->{
p.getProperty(x.toString(), new File(y.toString()).getName());
};
p.forEach(bi);
}
return p;
}
示例11: loadPropertyFile
import java.util.Properties; //導入方法依賴的package包/類
static void loadPropertyFile(String filename) {
try (InputStream in = new FileInputStream(filename)) {
Properties prop = new Properties();
prop.loadFromXML(in);
verifyProperites(prop);
} catch (IOException ex) {
fail(ex.getMessage());
}
}
示例12: testLoadWithBadEncoding
import java.util.Properties; //導入方法依賴的package包/類
/**
* Test loadFromXML with unsupported encoding
*/
static void testLoadWithBadEncoding() throws IOException {
System.out.println("testLoadWithBadEncoding");
String s = "<?xml version=\"1.0\" encoding=\"BAD\"?>" +
"<!DOCTYPE properties SYSTEM \"http://java.sun.com/dtd/properties.dtd\">" +
"<properties>" +
"<entry key=\"foo\">bar</entry>" +
"</properties>";
ByteArrayInputStream in = new ByteArrayInputStream(s.getBytes("UTF-8"));
Properties props = new Properties();
try {
props.loadFromXML(in);
throw new RuntimeException("UnsupportedEncodingException expected");
} catch (UnsupportedEncodingException expected) { }
}
示例13: convertXMLToProperties
import java.util.Properties; //導入方法依賴的package包/類
Properties convertXMLToProperties(String xmlString) {
Properties properties = new Properties();
try (InputStream in = new ByteArrayInputStream(xmlString.getBytes())) {
properties.loadFromXML(in);
} catch (IOException e) {
LOGGER.logError(Log4jLogger.SYSTEM_LOG, e,
LogMessageIdentifier.ERROR);
}
return properties;
}
示例14: getProperties
import java.util.Properties; //導入方法依賴的package包/類
private Properties getProperties() {
Properties properties = new Properties();
final InputStream is = getNamedData(PROPERTIES);
if (is != null) {
try {
properties.loadFromXML(is);
} catch (final IOException e) {
e.printStackTrace();
}
}
return properties;
}
示例15: convertXMLToProperties
import java.util.Properties; //導入方法依賴的package包/類
Properties convertXMLToProperties(String xmlString) {
Properties properties = new Properties();
try (InputStream in = new ByteArrayInputStream(xmlString.getBytes())) {
properties.loadFromXML(in);
} catch (IOException e) {
throw new RuntimeException();
}
return properties;
}