Holger's
Java API

com.antelmann.io
Class IniFile

java.lang.Object
  extended by java.io.File
      extended by com.antelmann.io.IniFile
All Implemented Interfaces:
Serializable, Comparable<File>

public class IniFile
extends File

a file that loads properties to standard *.ini conventions (unlike the class java.util.Properties)

Author:
Holger Antelmann
See Also:
Serialized Form

Field Summary
protected  String charset
          uses the default charset of this Java virtual machine by default
protected  char[] commentIndicator
          uses '#' and '[' by default, the array must never be empty
protected  String fieldSeparator
          uses the equal sign '=' by default
 
Fields inherited from class java.io.File
pathSeparator, pathSeparatorChar, separator, separatorChar
 
Constructor Summary
IniFile(File file)
           
IniFile(File file, String charset)
           
 
Method Summary
protected  boolean isCommentLine(String line)
          checks whether the line is considered a comment.
protected  String[] parseLine(String line)
          returns either null or an array of size 2, containing key/value pair.
 Properties readProperties()
           
 IniFile setCommentIndicator(char... commentIndicator)
          returns this
 IniFile setFieldSeparator(String fieldSeparator)
          returns this
 void store(Properties props, String comment)
           
 
Methods inherited from class java.io.File
canRead, canWrite, compareTo, createNewFile, createTempFile, createTempFile, delete, deleteOnExit, equals, exists, getAbsoluteFile, getAbsolutePath, getCanonicalFile, getCanonicalPath, getName, getParent, getParentFile, getPath, hashCode, isAbsolute, isDirectory, isFile, isHidden, lastModified, length, list, list, listFiles, listFiles, listFiles, listRoots, mkdir, mkdirs, renameTo, setLastModified, setReadOnly, toString, toURI, toURL
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

fieldSeparator

protected String fieldSeparator
uses the equal sign '=' by default


commentIndicator

protected char[] commentIndicator
uses '#' and '[' by default, the array must never be empty


charset

protected String charset
uses the default charset of this Java virtual machine by default

Constructor Detail

IniFile

public IniFile(File file)

IniFile

public IniFile(File file,
               String charset)
Method Detail

setFieldSeparator

public IniFile setFieldSeparator(String fieldSeparator)
returns this


setCommentIndicator

public IniFile setCommentIndicator(char... commentIndicator)
returns this


readProperties

public Properties readProperties()
                          throws IOException
Throws:
IOException

parseLine

protected String[] parseLine(String line)
returns either null or an array of size 2, containing key/value pair. Note that if the key is zero-length, null is returned instead of the array. If the value is zero-length, the key is returned at index 0 of the array, whereas the value is then returned as an empty string at index 1. I.e. if a non-null value is returned, the elements of the array are also non-null. In case the line is empty or considered a comment, null is returned. If This method checks first whether the given line is a comment line; if so, null is returned.

See Also:
isCommentLine(String)

isCommentLine

protected boolean isCommentLine(String line)
checks whether the line is considered a comment. A line is considered a comment if it is either null, zero-length or it starts with a character in the commentIndicator.


store

public void store(Properties props,
                  String comment)
           throws IOException
Throws:
IOException


(c) 2001-2006 Holger Antelmann - all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads