A DESCRIPTION OF THE REQUEST :
This is an RFE for two convenience classes which would make simple name-value file parsing trivial and without having to define a DTD and go the XML route with Swing's Parser. The classes would probably be a subclass of File or FileReader/FileWriter. Let us call them ParamReader and ParamWriter.
The first one would take a {file, file descriptor, input stream} and a delimiter as its constructor and the second the same, changing input stream to output stream.
Then, ParamReader would have get functions that returned a map with the names as keys and the values as values or a single value given a key.
ParamWriter would have write functions to write out its contents to a file, either in total or by name. For the in total version, there should be a boolean to determine whether it discards pairs with no key in its map and for both there should be an overwrite/insert toggle. ParamWriter should not treat any non-delimiter character as special in any way, including quotation marks, escaped characters and so on.
Some thought will have to be given to multiple pairs with the same key. The simplest solutions are either first value in file or last. No promises should be made about the ordering of pairs in the file.
JUSTIFICATION :
The use of name-value parameter files is widespread and many Solaris commands behave this way. An example would be smpatch get (ParamReader) and smpatch set (ParamWriter). Thus, the argument is not that this is difficult for developers to do, but rather API utility and possible performance optimizations.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Given a file that looks like this:
foo = f
bar = b
baz = z
1) be able to return a Map which logically looks like:
(foo,f)
(bar,b)
(baz,z)
2) given foo, return f
3) given "qux" and "q" and either true or false, add to the file:
qux = q
4) given "foo", "o", false, do nothing.
given "foo", "o", true, change the line in the file to:
foo = o
5) total file behavior as described above
ACTUAL -
RFE - N/A
CUSTOMER SUBMITTED WORKAROUND :
Write my own code. ;)
###@###.### 2005-06-20 10:55:40 GMT
This is an RFE for two convenience classes which would make simple name-value file parsing trivial and without having to define a DTD and go the XML route with Swing's Parser. The classes would probably be a subclass of File or FileReader/FileWriter. Let us call them ParamReader and ParamWriter.
The first one would take a {file, file descriptor, input stream} and a delimiter as its constructor and the second the same, changing input stream to output stream.
Then, ParamReader would have get functions that returned a map with the names as keys and the values as values or a single value given a key.
ParamWriter would have write functions to write out its contents to a file, either in total or by name. For the in total version, there should be a boolean to determine whether it discards pairs with no key in its map and for both there should be an overwrite/insert toggle. ParamWriter should not treat any non-delimiter character as special in any way, including quotation marks, escaped characters and so on.
Some thought will have to be given to multiple pairs with the same key. The simplest solutions are either first value in file or last. No promises should be made about the ordering of pairs in the file.
JUSTIFICATION :
The use of name-value parameter files is widespread and many Solaris commands behave this way. An example would be smpatch get (ParamReader) and smpatch set (ParamWriter). Thus, the argument is not that this is difficult for developers to do, but rather API utility and possible performance optimizations.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Given a file that looks like this:
foo = f
bar = b
baz = z
1) be able to return a Map which logically looks like:
(foo,f)
(bar,b)
(baz,z)
2) given foo, return f
3) given "qux" and "q" and either true or false, add to the file:
qux = q
4) given "foo", "o", false, do nothing.
given "foo", "o", true, change the line in the file to:
foo = o
5) total file behavior as described above
ACTUAL -
RFE - N/A
CUSTOMER SUBMITTED WORKAROUND :
Write my own code. ;)
###@###.### 2005-06-20 10:55:40 GMT