All Packages Class Hierarchy This Package Previous Next Index
Class sdsu.io.StringizableReader
java.lang.Object
|
+----sdsu.io.StringizableReader
- public class StringizableReader
- extends Object
- implements Enumeration
Input (String, file, or reader) consists of:
optional whitespace followed by optional file metadata line
followed by one or more data blocks. A data block consists of
optional whitespace
followed by optional comment block, optional whitespace, followed
by optional metadata block,
optional whitespace, followed by optional comment block, followed
by data.
The file metadata line must be started with the two characters
##.
It can contain any of the following three name-value pairs:
DataSeparator=AString;CommentCharacter=A;MetaDataCharacter=B
The DataSeparator value is the string that separates
data blocks. It must be selected
not to clash with other strings in the file. The
CommentCharacter value,
which must be a single character, is used to indicate the start of
a line in a comment
block. The MetaDataCharacter value, which must be a single
character, is used
to indicate a meta data block (see below).
A comment block connsists of consecutive lines each starting
with a comment character,
which defaults to '#'. Comments are ignored. The comment block before
the metadata
block is called the metadata comment. The comment block before
the data is called the
data comment.
A metadata block consists of consecutive lines each starting with
a comment character
then the metadata character, which defaults to '$'. The metadata block
contains
name-value pairs used to read the data. The format of the name-value
pair is the
default format for the class sdsu.io.LabeledData, which is used to
interpret the
name-value pairs. The format is name=value;. That is the name
and value are
separated by the character '=', pairs are separated by the character
';'. White space
can be used. The last pair does not need to be followed by ';'.
If the value contains
either '=', ';' or whitespace it must be quoted by the single quote
character. For example:
message='hi mom'
There are two special name-value pairs. The
first is "class=AFullyQuallifiedClassName". If this name-value pair
does not exist
the data is read as a string. If this name-value pair does exist,
the class must
implement Stringizable. The indicated class, called the data
class.,
is used to interpret the data. The other
special name-value pair is "label=ALabelForTheData". This name-value
pair is used to label
the data block. Other name-values are used as required to help set
the state for the
data class. The name-value pairs can be on multiple lines, all pairs
in the block must be
followed by the ';' character, except the last one in the block.
If a data class is given in the meta data block, the meta data and
the data are used to
recreate an object that is an instance of the data class. The meta
data is used as the
argument to the objects setMetaData method. The data is used as the
arument to the
objects fromString method.
The nextElement method of this class returns the data for the next
data block. The
object returned is either a string (if there was no data class) or
is of type data
class.
- Version:
- 0.8 7 January 1998
- Author:
- Roger Whitney
(whitney@cs.sdsu.edu)
-
DEFAULT_COMMENT_CHAR
- Default character used at begining of a line to indicate
a comment, which ends at the end of line.
-
DEFAULT_DATA_BLOCK_SEPARATOR
- Default string that separates data block.
-
DEFAULT_METADATA_CHAR
- Default character that indicates
a line of metaData when it is the second character of a
comment line.
-
META_COMMENT_CHAR_KEY
- Name used in file meta data line to indicate the comment character.
-
META_DATA_CHAR_KEY
- Name used in file meta data line to indicate the meta data character.
-
META_SEPARATOR_KEY
- Name used in file meta data line to indicate the data
separator string.
-
StringizableReader(Reader)
- Create a StringizableReader object with a Reader as an input
and the
given separator.
-
StringizableReader(String)
- Create a StringizableReader object with a String as an input
and the
given separator.
-
fromFile(String)
- Create a StringizableReader object with a file as an input
and the
given separator.
-
getDataComment()
- Return the comment for the current data object
-
getDataLabel()
- Returns the label for the current data object.
-
hasMoreElements()
- Returns true if there are more blocks of data in the input.
-
nextElement()
- Returns the next block of data.
-
setSeparator(String)
-
META_SEPARATOR_KEY
public static final String META_SEPARATOR_KEY
- Name used in file meta data line to indicate the data
separator string.
META_COMMENT_CHAR_KEY
public static final String META_COMMENT_CHAR_KEY
- Name used in file meta data line to indicate the comment character.
META_DATA_CHAR_KEY
public static final String META_DATA_CHAR_KEY
- Name used in file meta data line to indicate the meta data character.
DEFAULT_COMMENT_CHAR
public static final char DEFAULT_COMMENT_CHAR
- Default character used at begining of a line to indicate
a comment, which ends at the end of line.
DEFAULT_METADATA_CHAR
public static final char DEFAULT_METADATA_CHAR
- Default character that indicates
a line of metaData when it is the second character of a
comment line.
DEFAULT_DATA_BLOCK_SEPARATOR
public static final String DEFAULT_DATA_BLOCK_SEPARATOR
- Default string that separates data block.
StringizableReader
public StringizableReader(Reader in) throws IOException
- Create a StringizableReader object with a Reader as an input
and the
given separator.
StringizableReader
public StringizableReader(String input) throws IOException
- Create a StringizableReader object with a String as an input
and the
given separator.
fromFile
public static StringizableReader fromFile(String fileName) throws FileNotFoundException, IOException
- Create a StringizableReader object with a file as an input
and the
given separator. File IO will be buffered for you.
- Throws: FileNotFoundException
- thrown if fileName is not
valid file name.
setSeparator
public void setSeparator(String newSeparator)
getDataComment
public String getDataComment()
- Return the comment for the current data object
getDataLabel
public String getDataLabel()
- Returns the label for the current data object.
Returns empty string, not null, if no label exists
hasMoreElements
public boolean hasMoreElements()
- Returns true if there are more blocks of data in the input.
nextElement
public Object nextElement()
- Returns the next block of data.
- Throws: NoSuchElementException
- if there are no
blocks of data left.
All Packages Class Hierarchy This Package Previous Next Index