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
All Implemented Interfaces:
XMLStorable

public class DelimSepValues
extends FieldContainer

A field container that stores and processed its contents as values separated by a pipe character: '|' (a different delimiter string can be specified by changing the "dsv.field.separator" property). Entries are separated by newlines (or by whitespace if the "dsv.entry.separator.ws" is set to true).

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 can be used to separate sections.

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.18 $, $Date: 2006/10/21 16:04:22 $, $Author: siefkes $
Author:
Christian Siefkes

Field Summary
static char COMMENT_START
          The character introducing a comment: '#'.
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, using the standard configuration.
DelimSepValues(Element element)
          Creates a new instance from an XML element, fulfilling the recommandation of the XMLStorable interface.
DelimSepValues(Element element, TiesConfiguration config)
          Creates a new instance from an XML element, fulfilling the recommandation of the XMLStorable interface.
DelimSepValues(String fieldSep, String entrySep, String[] fixedHeaderNames)
          Creates a new empty instance.
DelimSepValues(TiesConfiguration config)
          Creates a new empty instance.
 
Method Summary
 void read(CharSequence input)
          Reads data as delimiter-separated values.
 void read(CharSequence input, String[] keys)
          Reads data as delimiter-separated values, using a specified array of field names.
 void store(Writer writer)
          Serializes contents as delimiter-separated values.
 
Methods inherited from class de.fu_berlin.ties.io.FieldContainer
add, add, add, add, add, addKey, backgroundMap, createFieldContainer, createObjects, entryIterator, keyCount, keyIterator, read, read, recommendedExtension, size, store, storeContainerInFile, storeInFile, toElement, toElement, toElement, toElement, 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
Constructor Detail

DelimSepValues

public DelimSepValues()
Creates a new empty instance, using the standard configuration.


DelimSepValues

public DelimSepValues(TiesConfiguration config)
Creates a new empty instance.

Parameters:
config - used to configure this instance

DelimSepValues

public DelimSepValues(String fieldSep,
                      String entrySep,
                      String[] fixedHeaderNames)
Creates a new empty instance.

Parameters:
fieldSep - the field separator to use
entrySep - the entry separator to use
fixedHeaderNames - an optional fixed list of keys to use; if null, keys are read from/written to the first line of a DSV file

DelimSepValues

public DelimSepValues(Element element)
Creates a new instance from an XML element, fulfilling the recommandation of the XMLStorable interface. Uses the standard configuration to configure this instance.

Parameters:
element - the XML element containing the serialized representation

DelimSepValues

public DelimSepValues(Element element,
                      TiesConfiguration config)
Creates a new instance from an XML element, fulfilling the recommandation of the XMLStorable interface.

Parameters:
element - the XML element containing the serialized representation
config - used to configure this instance
Method Detail

read

public void read(CharSequence input)
Reads data as delimiter-separated values.

Overrides:
read in class FieldContainer
Parameters:
input - the input data to process

read

public void read(CharSequence input,
                 String[] keys)
Reads data as delimiter-separated values, using a specified array of field names.

Parameters:
input - the input data to process
keys - the array of field names; or null if the field names should be determined from the first line of the input

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-2007 Christian Siefkes. All Rights Reserved.