Re: [configuration] reading full text of PropertiesConfiguration file in 2.0
Didn't subscribe to list, found Oliver's kind reply on the archive site, don't know how to reply to that directly, so I'm replying to my original message. Oliver's suggestion worked fine, 2.0 code is: FileBasedConfigurationBuilder builder = new Configurations.propertiesBuilder("my.properties"); PropertiesConfiguration propertiesConfiguration = builder.getConfiguration(); FileHandler fileHandler = builder.getFileHandler(); URL url = fileHandler.getURL(); String cont = IOUtils.toString((InputStream) url.openConnection().getContent(), StandardCharsets.UTF_8); From: Robert V Sasseen <rvsass...@hotmail.com> Sent: Friday, November 11, 2016 6:47 PM To: user@commons.apache.org Subject: [configuration] reading full text of PropertiesConfiguration file in 2.0 Is there a straightforward way to get the full text of the properties file from a PropertiesConfiguration object in 2.0? In 1.x I could do PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration("my.properties"); URL url = propertiesConfiguration.getURL(); String cont = IOUtils.toString((InputStream) url.openConnection().getContent(), StandardCharsets.UTF_8); This worked for both properties file in my jar and in the filesystem on the classpath. But in 2.0 PropertiesConfiguration does not have a method getURL(). Since PropertiesConfiguration has a (somewhat) complicated algorithm for finding properties in the classpath and filesystem, I want to let it carry out its algorithm, then ask it where it found the file, rather than having to try to understand and replicate the algorithm. If you're wondering why I want the text, I want to be able to show my user exactly what the file looks like, even if it's hidden away in a jar file. I know (a little) about PropertiesConfigurationLayout, but I'd prefer to just get the file text rather than reconstruct an approximation of it using that.
Re: [configuration] reading full text of PropertiesConfiguration file in 2.0
Hi Robert, Am 12.11.2016 um 03:47 schrieb Robert V Sasseen: > Is there a straightforward way to get the full text of the properties file > from a PropertiesConfiguration object in 2.0? In 1.x I could do > > > PropertiesConfiguration propertiesConfiguration = new > PropertiesConfiguration("my.properties"); > > URL url = propertiesConfiguration.getURL(); > String cont = IOUtils.toString((InputStream) > url.openConnection().getContent(), StandardCharsets.UTF_8); > > > This worked for both properties file in my jar and in the filesystem on the > classpath. But in 2.0 PropertiesConfiguration does not have a method getURL(). > > > Since PropertiesConfiguration has a (somewhat) complicated algorithm for > finding properties in the classpath and filesystem, I want to let it carry > out its algorithm, then ask it where it found the file, rather than having to > try to understand and replicate the algorithm. > > > If you're wondering why I want the text, I want to be able to show my user > exactly what the file looks like, even if it's hidden away in a jar file. I > know (a little) about PropertiesConfigurationLayout, but I'd prefer to just > get the file text rather than reconstruct an approximation of it using that. > If you use a FileBasedConfigurationBuilder to create the PropertiesConfiguration, you should be able to use the builder's getFileHandler() method to obtain a FileHandler object. This object has methods that allow you to retrieve the underlying file or URL. Oliver - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
[configuration] reading full text of PropertiesConfiguration file in 2.0
Is there a straightforward way to get the full text of the properties file from a PropertiesConfiguration object in 2.0? In 1.x I could do PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration("my.properties"); URL url = propertiesConfiguration.getURL(); String cont = IOUtils.toString((InputStream) url.openConnection().getContent(), StandardCharsets.UTF_8); This worked for both properties file in my jar and in the filesystem on the classpath. But in 2.0 PropertiesConfiguration does not have a method getURL(). Since PropertiesConfiguration has a (somewhat) complicated algorithm for finding properties in the classpath and filesystem, I want to let it carry out its algorithm, then ask it where it found the file, rather than having to try to understand and replicate the algorithm. If you're wondering why I want the text, I want to be able to show my user exactly what the file looks like, even if it's hidden away in a jar file. I know (a little) about PropertiesConfigurationLayout, but I'd prefer to just get the file text rather than reconstruct an approximation of it using that.