Apache Commons Configuration2を使用してInputStreamからデータを読み取るにはどうすればよいですか?Apache Commons Configuration2 InputStreamからデータを読み取る方法
FileBasedConfigurationBuilder<XMLConfiguration> builder =
new FileBasedConfigurationBuilder<XMLConfiguration>(XMLConfiguration.class)
.configure(
new Parameters()
.xml()
.setFileName("")
.setExpressionEngine(new XPathExpressionEngine())
);
XMLConfiguration config = builder.getConfiguration();
config.read(sourceJarFile.getInputStream(sourcePropertiesEntry))
上記のコードを与えると、setFileNameに空の文字列が指定されている場合、以下の例外が発生します。
org.apache.commons.configuration2.ex.ConfigurationException: Could not locate: [email protected][fileName=tmp.xml,basePath=<null>,sourceURL=,encoding=<null>,fileSystem=<null>,locationStrategy=<null>]
at org.apache.commons.configuration2.io.FileLocatorUtils.locateOrThrow(FileLocatorUtils.java:346)
at org.apache.commons.configuration2.io.FileHandler.load(FileHandler.java:972)
at org.apache.commons.configuration2.io.FileHandler.load(FileHandler.java:702)
at org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder.initFileHandler(FileBasedConfigurationBuilder.java:312)
at org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder.initResultInstance(FileBasedConfigurationBuilder.java:291)
at org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder.initResultInstance(FileBasedConfigurationBuilder.java:60)
at org.apache.commons.configuration2.builder.BasicConfigurationBuilder.createResult(BasicConfigurationBuilder.java:421)
at org.apache.commons.configuration2.builder.BasicConfigurationBuilder.getConfiguration(BasicConfigurationBuilder.java:285)
at com.test.installer.App.getXMLConfigurationProperties(App.java:185)
nullを指定した場合、またはsetFileName()を呼び出さない場合は、私はread()行で設定例外を読み込むことができません。
org.apache.commons.configuration2.ex.ConfigurationException: Unable to load the configuration
at org.apache.commons.configuration2.XMLConfiguration.load(XMLConfiguration.java:986)
at org.apache.commons.configuration2.XMLConfiguration.read(XMLConfiguration.java:954)
at com.test.installer.App.updateExistedProperties(App.java:84)