de.fu_berlin.ties.io
Class DelimSepValues

java.lang.Object
  extended by de.fu_berlin.ties.io.FieldContainer
      extended by de.fu_berlin.ties.io.DelimSepValues

public class DelimSepValues
extends FieldContainer

A field container that stores and processed its contents as values separated by a pipe character ('|'). Entries are separated by newlines.

The very first non-comment line contains the field names, separated by pipes. Each further non-comment lines contains the values of a entry (FieldMap). The first non-comment line must contain as least as most pipes as each further line, so the field names are known for all fields of all field maps. Empty fields are ignored when populating field maps.

The '#' character can be used to introduce comment lines. Comments and lines that are empty or contain only whitespace are ignored when reading data.

Pipe characters and newlines within fields and '#' at the begin of the first field of an entry are escaped with a backslash. The recommended character set for storing delimiter-separated values is UTF-8.

Floats and doubles are formatted (rounded) via Util.format(double).

Version:
$Revision: 1.4 $, $Date: 2004/09/06 17:23:31 $, $Author: siefkes $
Author:
Christian Siefkes

Field Summary
static char COMMENT_START
          The character introducing a comment: '#'.
static char DELIM
          The field delimiter character: '|' (a pipe).
static char ESCAPE
          The escape character: '\' (a backslash).
static String FILE_EXT
          The recommended file extension for this format: "dsv" (delimiter-separated values).
 
Constructor Summary
DelimSepValues()
          Creates a new empty instance.
DelimSepValues(CharSequence input)
          Creates a new instance from serialized delimiter-separated values.
DelimSepValues(InputStream in)
          Creates a new instance from serialized delimiter-separated values.
DelimSepValues(Reader reader)
          Creates a new instance from serialized delimiter-separated values.
DelimSepValues(StorableContainer contents)
          Creates a new instance and populates it from a StorableContainer.
 
Method Summary
 void store(Writer writer)
          Serializes contents as delimiter-separated values.
 
Methods inherited from class de.fu_berlin.ties.io.FieldContainer
add, add, add, add, addKey, attributeCount, attributeIterator, backgroundMap, createFieldContainer, createFieldContainer, createFieldContainer, createFieldContainer, createNestedContainer, createObjects, entryIterator, getAttribute, getNestedContainer, keyCount, keyIterator, nestedCount, nestedIterator, recommendedExtension, setAttribute, size, store, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FILE_EXT

public static final String FILE_EXT
The recommended file extension for this format: "dsv" (delimiter-separated values).

See Also:
Constant Field Values

COMMENT_START

public static final char COMMENT_START
The character introducing a comment: '#'.

See Also:
Constant Field Values

ESCAPE

public static final char ESCAPE
The escape character: '\' (a backslash).

See Also:
Constant Field Values

DELIM

public static final char DELIM
The field delimiter character: '|' (a pipe).

See Also:
Constant Field Values
Constructor Detail

DelimSepValues

public DelimSepValues()
Creates a new empty instance.


DelimSepValues

public DelimSepValues(CharSequence input)
               throws IllegalArgumentException
Creates a new instance from serialized delimiter-separated values.

Parameters:
input - the input data to process
Throws:
IllegalArgumentException - if the input data contains errors, e.g. when there are insufficient field names given in the first non-comment line

DelimSepValues

public DelimSepValues(InputStream in)
               throws IOException,
                      IllegalArgumentException
Creates a new instance from serialized delimiter-separated values.

Parameters:
in - a stream containing the input data to process, must use the UTF-8 charset; the stream is not closed by this method
Throws:
IOException - if an I/O error occurs while reading from the stream
IllegalArgumentException - if the input data contains errors, esp. when there are insufficient field names given in the first non-comment line

DelimSepValues

public DelimSepValues(Reader reader)
               throws IOException,
                      IllegalArgumentException
Creates a new instance from serialized delimiter-separated values.

Parameters:
reader - a reader containing the input data to process; not closed by this method
Throws:
IOException - if an I/O error occurs while reading
IllegalArgumentException - if the input data contains errors, esp. when there are insufficient field names given in the first non-comment line

DelimSepValues

public DelimSepValues(StorableContainer contents)
Creates a new instance and populates it from a StorableContainer.

Parameters:
contents - the contents to add by calling StorableContainer.storeEntries(FieldContainer)
Method Detail

store

public void store(Writer writer)
           throws IOException
Serializes contents as delimiter-separated values.

Overrides:
store in class FieldContainer
Parameters:
writer - the writer to write to; flushed but not closed by this method
Throws:
IOException - if an I/O error occurs while writing to the stream


Copyright © 2003-2004 Christian Siefkes. All Rights Reserved.