com.taleo.integration.client.customstep.util.csv
Class CsvUtils

java.lang.Object
  extended by com.taleo.integration.client.customstep.util.csv.CsvUtils

public class CsvUtils
extends java.lang.Object

Utility class for CSV.

Author:
Romain Guay, Taleo Corporation

Constructor Summary
CsvUtils()
           
 
Method Summary
static java.lang.Object deserializeBase64(java.lang.String base64)
          Deserialize a Base64 string into an object.
static int getColumnIndex(java.lang.String column, java.lang.String[] header)
          Get the index for the given column name or index.
static int[] getColumnIndexes(java.lang.String[] columns, java.lang.String[] header)
          Get the columns indexes, transforming names into indexes if required.
static java.lang.String[] readFirstLine(java.io.Reader reader, char csvDelimiter, char csvQuoteCharacter)
          Read the first line from the given reader.
static java.lang.String[] readLine(java.io.Reader reader, char csvDelimiter, char csvQuoteCharacter, int lineNumber)
          Read the given line number from the given reader.
static java.lang.String serializeBase64(java.lang.Object object)
          Serialize an object into a Base64 string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CsvUtils

public CsvUtils()
Method Detail

readFirstLine

public static java.lang.String[] readFirstLine(java.io.Reader reader,
                                               char csvDelimiter,
                                               char csvQuoteCharacter)
                                        throws java.io.IOException,
                                               InvalidCSVFileFormat
Read the first line from the given reader.

Parameters:
reader - The reader containing the CSV.
csvDelimiter -
csvQuoteCharacter -
Returns:
If the first line is the header, it is returned. If there is no header, the first record is returned. If the file is empty, an empty array is returned.
Throws:
InvalidCSVFileFormat
java.io.IOException

readLine

public static java.lang.String[] readLine(java.io.Reader reader,
                                          char csvDelimiter,
                                          char csvQuoteCharacter,
                                          int lineNumber)
                                   throws java.io.IOException,
                                          InvalidCSVFileFormat
Read the given line number from the given reader.

Parameters:
reader - The reader containing the CSV.
csvDelimiter -
csvQuoteCharacter -
lineNumber - The line number (1 based).
Returns:
The line in a String array. If the file is empty, an empty array is returned.
Throws:
InvalidCSVFileFormat
java.io.IOException

getColumnIndex

public static int getColumnIndex(java.lang.String column,
                                 java.lang.String[] header)
                          throws java.lang.ArrayIndexOutOfBoundsException
Get the index for the given column name or index. If column is numeric, it is considered an index already, otherwise the index is found in the header. Column name comparison ignores case.

Parameters:
column - The column name or index.
header - The CSV header. May be null if column is numeric.
Returns:
The column index.
Throws:
java.lang.ArrayIndexOutOfBoundsException - If the column name is not found in the header.

getColumnIndexes

public static int[] getColumnIndexes(java.lang.String[] columns,
                                     java.lang.String[] header)
Get the columns indexes, transforming names into indexes if required. Column name comparison ignores case.

Parameters:
columns - The columns name or index.
header - The CSV header. May be null if all columns are numeric.
Returns:
The column indexes.
Throws:
java.lang.ArrayIndexOutOfBoundsException - If a column name is not found in the header.

serializeBase64

public static java.lang.String serializeBase64(java.lang.Object object)
                                        throws java.io.IOException
Serialize an object into a Base64 string.

Parameters:
object - The object.
Returns:
Throws:
java.io.IOException

deserializeBase64

public static java.lang.Object deserializeBase64(java.lang.String base64)
                                          throws java.io.IOException,
                                                 java.lang.ClassNotFoundException
Deserialize a Base64 string into an object.

Parameters:
base64 - The Base64 string.
Returns:
Throws:
java.io.IOException
java.lang.ClassNotFoundException