gitzel.util

Class IniReader

Known Direct Subclasses:
BasicScriptReader

public class IniReader
extends java.lang.Object

This class allows reading ini files from any input stream, file or http-doc. It is basically a portation of the c++ class InitReader, I wrote for LS PI4. Here is the original header file text: This class takes an input stream and extracts init-file infos. These are stored in a map and are accesible via methods. The input stream (usually a file) is parsed like this: HEADERNAME: DATA \n In order to parse other formats simply create a subclass to this one and overwrite the protected member 'parse' with your own function that suits your definition of an init file line.

Field Summary

private Map
Data
The Map to store all entries.
(package private) BufferedReader
IStream
The input stream we use...

Constructor Summary

IniReader(BufferedReader r)
IniReader(InputStream in)
Pass an input stream to the ini reader to have it know where to look...
IniReader(String data)
The IniReader takes the given String as input stream.

Method Summary

void
deleteEntry(String X)
delete the entry X
String
getEntry(String field)
gives the data correpsonding to the given entry.
protected void
parse(String line)
parses a line from the input file.
void
save(OutputStream o)
save the header info to the given output stream.
void
save(String filename)
a shortcut function that allows giving a file name instead of a stream for saving
boolean
setEntry(String X, String data)
alter header X information (use save function to update on disk as well).

Field Details

Data

private Map Data
The Map to store all entries.

IStream

(package private)  BufferedReader IStream
The input stream we use...

Constructor Details

IniReader

public IniReader(BufferedReader r)
            throws IOException

IniReader

public IniReader(InputStream in)
            throws IOException
Pass an input stream to the ini reader to have it know where to look...

IniReader

public IniReader(String data)
            throws IOException
The IniReader takes the given String as input stream.

Method Details

deleteEntry

public void deleteEntry(String X)
delete the entry X

getEntry

public String getEntry(String field)
gives the data correpsonding to the given entry. If entry does not exist, an empty string is returned.

parse

protected void parse(String line)
parses a line from the input file. This function is 'virtual' to allow easy creation of other file formats via subclasses and overwriting this method.

save

public void save(OutputStream o)
save the header info to the given output stream. A false indicates failure

save

public void save(String filename)
            throws FileNotFoundException
a shortcut function that allows giving a file name instead of a stream for saving

setEntry

public boolean setEntry(String X,
                        String data)
alter header X information (use save function to update on disk as well). Function returns true if the header did not exist yet (this indicates that a new entry was created).