com.isti.util
Class DelimiterSeparatedValues

java.lang.Object
  extended by com.isti.util.DelimiterSeparatedValues

public class DelimiterSeparatedValues
extends java.lang.Object


Field Summary
static java.lang.String DEFAULT_COMMENT_TEXT
          The default comment text.
static char DEFAULT_DELIMITER_CHAR
          The default delimiter character.
static char DEFAULT_ESCAPE_CHAR
          The default escape character.
static java.lang.String DEFAULT_ESCAPED_CHARS
          The default characters that should be escaped.
static java.lang.String DEFAULT_LINE_SEPARATOR
          The default line separator.
static java.lang.String STANDARD_COMMENT_TEXT
          The standard comment text.
static int USE_QUOTES_ALWAYS
          Use quotes value to specify that quotes should always be used.
static int USE_QUOTES_AS_NEEDED
          Use quotes value to specify that quotes should be used as needed.
static int USE_QUOTES_NEVER
          Use quotes value to specify that quotes should never be used.
 
Constructor Summary
DelimiterSeparatedValues()
          Creates comma-separated values (CSV) without comment text.
DelimiterSeparatedValues(java.lang.String commentText)
          Creates comma-separated values (CSV) with optional comment text.
DelimiterSeparatedValues(java.lang.String commentText, char delimiterChar, java.lang.String escapeChars, char escapeChar)
          Creates delimiter-separated values.
DelimiterSeparatedValues(java.lang.String commentText, char delimiterChar, java.lang.String escapedChars, char escapeChar, java.lang.String reservedChars)
          Creates delimiter-separated values.
 
Method Summary
 java.lang.String getLineSeparator()
          Gets the line separator.
 java.lang.String getQuotedText(java.lang.String valueStr)
          Gets a quoted string where all quote characters are replaced by double quote characters.
static java.lang.String getReservedChars(char delimiterChar)
          Gets the reserverd characters.
 int getUseQuotesValue()
          Gets the use quotes value.
 int getUseQuotesValue(int column)
          Gets the use quotes value for the specified column.
 java.lang.String getValueStr(java.lang.Object valueObj)
          Gets the value string for the value object.
static void main(java.lang.String[] args)
           
 void readNext(java.io.BufferedReader br, java.util.List valueList, java.lang.StringBuffer valueBuffer)
          Read the next set of fields.
 void setLineSeparator(java.lang.String lineSeparator)
          Sets the line separator.
 void setUseQuotesValue(int v)
          Sets the use quotes value.
 void setUseQuotesValue(int[] v)
          Sets the use quotes value array.
 boolean shouldBeQuoted(java.lang.String valueStr, int column)
          Determines if the value should be quoted.
 void writeNext(java.io.Writer w, java.util.List valueList)
          Write the values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_COMMENT_TEXT

public static final java.lang.String DEFAULT_COMMENT_TEXT
The default comment text.


STANDARD_COMMENT_TEXT

public static final java.lang.String STANDARD_COMMENT_TEXT
The standard comment text.

See Also:
Constant Field Values

DEFAULT_DELIMITER_CHAR

public static final char DEFAULT_DELIMITER_CHAR
The default delimiter character.

See Also:
Constant Field Values

DEFAULT_ESCAPED_CHARS

public static final java.lang.String DEFAULT_ESCAPED_CHARS
The default characters that should be escaped.

See Also:
Constant Field Values

DEFAULT_ESCAPE_CHAR

public static final char DEFAULT_ESCAPE_CHAR
The default escape character.

See Also:
Constant Field Values

DEFAULT_LINE_SEPARATOR

public static final java.lang.String DEFAULT_LINE_SEPARATOR
The default line separator.


USE_QUOTES_NEVER

public static final int USE_QUOTES_NEVER
Use quotes value to specify that quotes should never be used.

See Also:
Constant Field Values

USE_QUOTES_AS_NEEDED

public static final int USE_QUOTES_AS_NEEDED
Use quotes value to specify that quotes should be used as needed.

See Also:
Constant Field Values

USE_QUOTES_ALWAYS

public static final int USE_QUOTES_ALWAYS
Use quotes value to specify that quotes should always be used.

See Also:
Constant Field Values
Constructor Detail

DelimiterSeparatedValues

public DelimiterSeparatedValues()
Creates comma-separated values (CSV) without comment text.


DelimiterSeparatedValues

public DelimiterSeparatedValues(java.lang.String commentText)
Creates comma-separated values (CSV) with optional comment text.

Parameters:
commentText - the text that starts comment lines or null if none.
See Also:
STANDARD_COMMENT_TEXT

DelimiterSeparatedValues

public DelimiterSeparatedValues(java.lang.String commentText,
                                char delimiterChar,
                                java.lang.String escapeChars,
                                char escapeChar)
Creates delimiter-separated values.

Parameters:
commentText - the text that starts comment lines or null if none.
delimiterChar - the delimiter character.
escapeChars - the characters that should be escaped. This should always contain the escape character.
escapeChar - the escape character.

DelimiterSeparatedValues

public DelimiterSeparatedValues(java.lang.String commentText,
                                char delimiterChar,
                                java.lang.String escapedChars,
                                char escapeChar,
                                java.lang.String reservedChars)
Creates delimiter-separated values.

Parameters:
commentText - the text that starts comment lines or null if none.
delimiterChar - the delimiter character.
escapedChars - the characters that should be escaped. This should always contain the escape character.
escapeChar - the escape character.
reservedChars - the reserved characters that should be quoted.
See Also:
getReservedChars
Method Detail

getLineSeparator

public java.lang.String getLineSeparator()
Gets the line separator.

Returns:
the line separator.

getQuotedText

public java.lang.String getQuotedText(java.lang.String valueStr)
Gets a quoted string where all quote characters are replaced by double quote characters.

Parameters:
valueStr - the value string or null if none.
Returns:
a quoted string or null if none.

getReservedChars

public static java.lang.String getReservedChars(char delimiterChar)
Gets the reserverd characters.

Parameters:
delimiterChar - the delimiter character.
Returns:
the reserverd characters.

getUseQuotesValue

public int getUseQuotesValue()
Gets the use quotes value.

Returns:
the use quotes value.
See Also:
USE_QUOTES_NEVER, USE_QUOTES_AS_NEEDED, USE_QUOTES_ALWAYS

getUseQuotesValue

public int getUseQuotesValue(int column)
Gets the use quotes value for the specified column.

Parameters:
column - the column.
Returns:
the use quotes value.
See Also:
USE_QUOTES_NEVER, USE_QUOTES_AS_NEEDED, USE_QUOTES_ALWAYS

getValueStr

public java.lang.String getValueStr(java.lang.Object valueObj)
Gets the value string for the value object.

Parameters:
valueObj - the value object or null if none.
Returns:
the value string or null if none.

readNext

public void readNext(java.io.BufferedReader br,
                     java.util.List valueList,
                     java.lang.StringBuffer valueBuffer)
              throws java.io.IOException
Read the next set of fields.

Parameters:
br - the buffered reader.
valueBuffer - the value buffer.
valueList - the list of string values. This list is normally empty when this method is called and is filled by this method.
Throws:
java.io.IOException - if error.

setLineSeparator

public void setLineSeparator(java.lang.String lineSeparator)
Sets the line separator.

Parameters:
lineSeparator - the line separator.

setUseQuotesValue

public void setUseQuotesValue(int v)
Sets the use quotes value. The use quotes value is normally USE_QUOTES_AS_NEEDED. If quotes are never used (USE_QUOTES_NEVER), the values should not contain any reserved characters, which are normally '\n', '\r', '"', and the delimiter character (the default delimiter character is ','.)

Parameters:
v - the use quotes value.
See Also:
USE_QUOTES_NEVER, USE_QUOTES_AS_NEEDED, USE_QUOTES_ALWAYS

setUseQuotesValue

public void setUseQuotesValue(int[] v)
Sets the use quotes value array. This array is indexed by the column. The use quotes value is normally USE_QUOTES_AS_NEEDED. If quotes are never used (USE_QUOTES_NEVER), the values should not contain any reserved characters, which are normally '\n', '\r', '"', and the delimiter character (the default delimiter character is ','.)

Parameters:
v - the use quotes value array or null if none.
See Also:
USE_QUOTES_NEVER, USE_QUOTES_AS_NEEDED, USE_QUOTES_ALWAYS

shouldBeQuoted

public boolean shouldBeQuoted(java.lang.String valueStr,
                              int column)
Determines if the value should be quoted.

Parameters:
valueStr - the value string or null if none.
column - the column where 0 is the first column.
Returns:
true if the value should be quoted, false otherwise.

writeNext

public void writeNext(java.io.Writer w,
                      java.util.List valueList)
               throws java.io.IOException
Write the values.

Parameters:
w - the writer.
valueList - the list of values.
Throws:
java.io.IOException - if error.

main

public static void main(java.lang.String[] args)