In a prior post “A very simple data file metaformat” I presented an idea for an INI type of file and used an example implementation in the Groovy language.
I rewrote it in Java. One change was the use of section terminators. I’m still not sure about specifying of the data type in the section header.
Note the only testing of this is the embedded JUnit tests as shown in the source.
Update: A version of this is being successfully used to store test data for a suite of unit tests. Each file holds several sections with hundreds of lines each of XML and other types.
- load(): Load all sections into a map.
- load(String id, String subsection): Load a specific section.
T loadAs(final Class: load a section as the given class type type, final String id, final String subsection)
- next(): Pull event style reading.
void parse(final BufferedReader reader,: Push event style reading.
- void parse(final String filePath, final Runnable runnable): Push event style reading.
Update 1 20121208T1809-5
Java Jar manifest files have a very useful property. Attributes which are in the ‘main’ section are inherited by individual entries unless redefined in the entry. For the application I envisioned this metaformat, that would be ideal. One way of doing this is that any data contained in a section ‘x’ is also applicable or in scope for any section x/y. And, so forth, x/y/z would have the data in x/y available.
Update 2 20130107T2000-5
Added method Map
Update 3 20130113T1300-5
Added loadAs(…) to make loading specific types easier.
Update 4 20131028T0939-5
Doh, forgot about mentioning Apache Commons Configuration. It does support hierarchical INI files. However, the sections in that format only support property mappings.
The test data file is:
# Example very simple data file ! Another comment #[>map:/junk] #[<] [>list:credit/tests] one two three [<] [>credit/report] one,two,three [<] [>properties:credit/config] one=alpha two=beta three=charlie [<] [>xml:credit/beans] <description> <item>one</item> <item>two</item> <item>three</item> </description> [<] [>notype/sub] [<] [>credit/alerts] ["one","two","three"] [<] [>credit] one two three [<] [>credit/coverages] ["one","two","three"] [<]
- INI file
- Java Properties file format
- Data File Metaformats
- Here document
- JSON configuration file format
- Groovy Object Notation (GrON) for Data
- Cloanto Implementation of INI File Format
- A very simple data file metaformat
- Groovy implementation of INIX file format, part 2
- Groovy implementation of INIX file format
- Groovy Object Notation using ConfigSlurper
- Java Typesafe Heterogeneous Container Example