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

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

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

Properties.loadFromXML介绍

[英]Loads the properties from an InputStream containing the properties in XML form. The XML document must begin with (and conform to) following DOCTYPE:

<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">

Also the content of the XML data must satisfy the DTD but the xml is not validated against it. The DTD is not loaded from the SYSTEM ID. After this method returns the InputStream is not closed.
[中]从包含XML格式属性的InputStream加载属性。XML文档必须以以下DOCTYPE开头(并符合该DOCTYPE):

<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">

此外,XML数据的内容必须满足DTD,但XML不会根据DTD进行验证。DTD未从系统ID加载。此方法返回后,InputStream未关闭。

代码示例

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

@Override
public void loadFromXml(Properties props, InputStream is) throws IOException {
  props.loadFromXML(is);
}

代码示例来源:origin: org.springframework/spring-core

@Override
public void loadFromXml(Properties props, InputStream is) throws IOException {
  props.loadFromXML(is);
}

代码示例来源:origin: alibaba/TProfiler

public void loadFromXML(InputStream in) throws IOException,
 InvalidPropertiesFormatException {
 delegate.loadFromXML(in);
}

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

/**
 * Fill the given properties from the given resource (in ISO-8859-1 encoding).
 * @param props the Properties instance to fill
 * @param resource the resource to load from
 * @throws IOException if loading failed
 */
public static void fillProperties(Properties props, Resource resource) throws IOException {
  InputStream is = resource.getInputStream();
  try {
    String filename = resource.getFilename();
    if (filename != null && filename.endsWith(XML_FILE_EXTENSION)) {
      props.loadFromXML(is);
    }
    else {
      props.load(is);
    }
  }
  finally {
    is.close();
  }
}

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

public SetupPreferences () {		
  if (!file.exists()) return;
  InputStream in = null;
  try {
    in = new BufferedInputStream(new FileInputStream(file));
    properties.loadFromXML(in);
  } catch (Throwable t) {
    t.printStackTrace();
  } finally {
    if (in != null)
      try {
        in.close();
      } catch (IOException e) {
      }
  }
}

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

try {
  if (resourceName.endsWith(XML_FILE_EXTENSION)) {
    props.loadFromXML(is);

代码示例来源:origin: pentaho/pentaho-kettle

@Override
public synchronized void loadFromXML( InputStream in ) throws IOException, InvalidPropertiesFormatException {
 super.putAll( storageMap );
 super.loadFromXML( in );
 super.forEach( ( key, value ) -> storageMap.putIfAbsent( key, value ) );
 super.clear();
}

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

@Override
public synchronized void loadFromXML(InputStream inStream) throws IOException {
 if (interned != null) copyFromInternedToThis();
 super.loadFromXML(inStream);
}

代码示例来源:origin: org.springframework/spring-core

/**
 * Fill the given properties from the given resource (in ISO-8859-1 encoding).
 * @param props the Properties instance to fill
 * @param resource the resource to load from
 * @throws IOException if loading failed
 */
public static void fillProperties(Properties props, Resource resource) throws IOException {
  InputStream is = resource.getInputStream();
  try {
    String filename = resource.getFilename();
    if (filename != null && filename.endsWith(XML_FILE_EXTENSION)) {
      props.loadFromXML(is);
    }
    else {
      props.load(is);
    }
  }
  finally {
    is.close();
  }
}

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

public Lwjgl3Preferences (FileHandle file) {
  this.file = file;
  if (!file.exists()) return;
  InputStream in = null;
  try {
    in = new BufferedInputStream(file.read());
    properties.loadFromXML(in);
  } catch (Throwable t) {
    t.printStackTrace();
  } finally {
    StreamUtils.closeQuietly(in);
  }
}

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

public HeadlessPreferences(FileHandle file) {
  this.file = file;
  if (!file.exists()) return;
  InputStream in = null;
  try {
    in = new BufferedInputStream(file.read());
    properties.loadFromXML(in);
  } catch (Throwable t) {
    t.printStackTrace();
  } finally {
    StreamUtils.closeQuietly(in);
  }
}

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

public HeadlessPreferences(FileHandle file) {
  this.file = file;
  if (!file.exists()) return;
  InputStream in = null;
  try {
    in = new BufferedInputStream(file.read());
    properties.loadFromXML(in);
  } catch (Throwable t) {
    t.printStackTrace();
  } finally {
    StreamUtils.closeQuietly(in);
  }
}

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

public Lwjgl3Preferences (FileHandle file) {
  this.file = file;
  if (!file.exists()) return;
  InputStream in = null;
  try {
    in = new BufferedInputStream(file.read());
    properties.loadFromXML(in);
  } catch (Throwable t) {
    t.printStackTrace();
  } finally {
    StreamUtils.closeQuietly(in);
  }
}

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

void load(String file) throws IOException {
  try {
    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"));
  } catch (InvalidPropertiesFormatException e) {
    throw new RuntimeException("Configuration file is not a valid XML document", e);
  }
}

代码示例来源:origin: pentaho/pentaho-kettle

public Properties getKettleProperties() throws Exception {
 String xml = execService( GetPropertiesServlet.CONTEXT_PATH + "/?xml=Y" );
 String decryptedXml = Encr.decryptPassword( xml );
 InputStream in = new ByteArrayInputStream( decryptedXml.getBytes() );
 Properties properties = new Properties();
 properties.loadFromXML( in );
 return properties;
}

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

/**
 * Determines if the the input stream is xml if it is, use create properties loaded from xml
 * format, otherwise create properties from default format.
 *
 * @param in
 * @throws IOException
 */
public static Properties loadUniversal(InputStream in) throws IOException {
  final String xmlDeclarationStart = "<?xml";
  BufferedInputStream bin = new BufferedInputStream(in);
  bin.mark(4096);
  BufferedReader reader = new BufferedReader(new InputStreamReader(bin));
  String line = reader.readLine();
  boolean isXML = line.startsWith(xmlDeclarationStart);
  bin.reset();
  Properties props = new Properties();
  if (isXML) props.loadFromXML(bin);
  else props.load(bin);
  return props;
}

代码示例来源:origin: alibaba/druid

properties.loadFromXML(inStream);
} else {
  properties.load(inStream);

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

public LwjglPreferences (FileHandle file) {
  this.name = file.name();
  this.file = file;
  if (!file.exists()) return;
  InputStream in = null;
  try {
    in = new BufferedInputStream(file.read());
    properties.loadFromXML(in);
  } catch (Throwable t) {
    t.printStackTrace();
  } finally {
    StreamUtils.closeQuietly(in);
  }
}

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

public LwjglPreferences (FileHandle file) {
  this.name = file.name();
  this.file = file;
  if (!file.exists()) return;
  InputStream in = null;
  try {
    in = new BufferedInputStream(file.read());
    properties.loadFromXML(in);
  } catch (Throwable t) {
    t.printStackTrace();
  } finally {
    StreamUtils.closeQuietly(in);
  }
}

代码示例来源:origin: medcl/elasticsearch-analysis-ik

private Dictionary(Configuration cfg) {
  this.configuration = cfg;
  this.props = new Properties();
  this.conf_dir = cfg.getEnvironment().configFile().resolve(AnalysisIkPlugin.PLUGIN_NAME);
  Path configFile = conf_dir.resolve(FILE_NAME);
  InputStream input = null;
  try {
    logger.info("try load config from {}", configFile);
    input = new FileInputStream(configFile.toFile());
  } catch (FileNotFoundException e) {
    conf_dir = cfg.getConfigInPluginDir();
    configFile = conf_dir.resolve(FILE_NAME);
    try {
      logger.info("try load config from {}", configFile);
      input = new FileInputStream(configFile.toFile());
    } catch (FileNotFoundException ex) {
      // We should report origin exception
      logger.error("ik-analyzer", e);
    }
  }
  if (input != null) {
    try {
      props.loadFromXML(input);
    } catch (InvalidPropertiesFormatException e) {
      logger.error("ik-analyzer", e);
    } catch (IOException e) {
      logger.error("ik-analyzer", e);
    }
  }
}

相关文章

微信公众号

最新文章

更多