net.sourceforge.jaulp.file.csv
Class CsvFileUtils

java.lang.Object
  extended by net.sourceforge.jaulp.file.csv.CsvFileUtils

public class CsvFileUtils
extends java.lang.Object

Utility class for the use of cvs-files.

Version:
1.0
Author:
Asterios Raptis

Constructor Summary
CsvFileUtils()
           
 
Method Summary
static void closeWriter(java.io.Writer writer)
          Deprecated. Use instead StreamUtils.closeWriter( Writer ).
static java.util.List formatKommaSeperatedFileToList(java.io.File input, java.lang.String encoding)
          Reads every line from the File splits the data through a comma and puts them to the List.
static void formatToCSV(java.io.File input, java.io.File output, java.lang.String encoding)
          Formats a file that has in every line one input-data into a csv-file.
static java.lang.String putQuotesToString(java.lang.String s)
          Deprecated. Use instead StringUtils.putQuotesToString( String ).
static java.util.List<java.lang.String> readDataFromCVSFileToList(java.io.File input, int position, boolean putFirstLine, java.lang.String encoding)
          Reads from a csv-file the field from the given position and puts them to the List.
static java.util.List<java.lang.String> readDataFromCVSFileToList(java.io.File input, int position, boolean putFirstLine, java.lang.String splitChar, java.lang.String encoding)
          Reads from a csv-file the field from the given position and puts them to the List.
static java.util.Properties readFilelistToProperties(java.io.File input)
          Read filelist to properties.
static java.util.List<java.lang.String> readFileToList(java.io.File file)
          Reads every line from the given File into a List and returns the List.
static java.util.List<java.lang.String> readFileToList(java.io.File file, java.lang.String encoding)
          Reads every line from the given File into a List and returns the List.
static java.util.List<java.lang.String> readLinesInList(java.io.File input, java.lang.String encoding)
          Reads every line from the File and puts them to the List.
static java.lang.String removeQuotesFromString(java.lang.String s)
          Deprecated. Use instead StringUtils.removeQuotesFromString(String).
static java.lang.String[] sortData(java.io.File csvData, java.lang.String encoding)
          Read an csv-file and puts them in a String-array.
static void storeFilelistToProperties(java.io.File output, java.io.File input, java.lang.String comments)
          Stores a komma seperated file to a properties object.
static void writeLines(java.io.File output, java.util.Set<java.lang.String> values, java.lang.String encoding)
          Writes the toString() value of each item in a collection to the specified File line by line.
static void writeLinesToFile(java.util.Collection<java.lang.String> collection, java.io.File output, java.lang.String encoding)
          Writes all the String-object in the collection into the given file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CsvFileUtils

public CsvFileUtils()
Method Detail

closeWriter

@Deprecated
public static void closeWriter(java.io.Writer writer)
Deprecated. Use instead StreamUtils.closeWriter( Writer ).

The Method closeWriter() closes the given Writer.

Parameters:
writer - The Writer to close.

formatKommaSeperatedFileToList

public static java.util.List formatKommaSeperatedFileToList(java.io.File input,
                                                            java.lang.String encoding)
Reads every line from the File splits the data through a comma and puts them to the List.

Parameters:
input - The File from where the input comes.
encoding - The encoding from the file.
Returns:
The List with all lines from the file.

formatToCSV

public static void formatToCSV(java.io.File input,
                               java.io.File output,
                               java.lang.String encoding)
                        throws java.io.IOException
Formats a file that has in every line one input-data into a csv-file.

Parameters:
input - The input-file to format. The current format from the file is every data in a line.
output - The file where the formatted data should be inserted.
Throws:
java.io.IOException - When an io error occurs.

putQuotesToString

@Deprecated
public static java.lang.String putQuotesToString(java.lang.String s)
Deprecated. Use instead StringUtils.putQuotesToString( String ).

Puts to the given String at the start and end quotes.

Parameters:
s - The String to handle.
Returns:
The String with quotes.

readDataFromCVSFileToList

public static java.util.List<java.lang.String> readDataFromCVSFileToList(java.io.File input,
                                                                         int position,
                                                                         boolean putFirstLine,
                                                                         java.lang.String encoding)
                                                                  throws java.io.IOException
Reads from a csv-file the field from the given position and puts them to the List.

Parameters:
input - The input-file.
position - The position from the field.
putFirstLine - Flag that tells if the first line will be put in the list.
Returns:
The list with the data.
Throws:
java.io.IOException - When a io-problem occurs.

readDataFromCVSFileToList

public static java.util.List<java.lang.String> readDataFromCVSFileToList(java.io.File input,
                                                                         int position,
                                                                         boolean putFirstLine,
                                                                         java.lang.String splitChar,
                                                                         java.lang.String encoding)
                                                                  throws java.io.IOException
Reads from a csv-file the field from the given position and puts them to the List.

Parameters:
input - The input-file.
position - The position from the field.
putFirstLine - Flag that tells if the first line will be put in the list.
Returns:
The list with the data.
Throws:
java.io.IOException - When a io-problem occurs.

readFilelistToProperties

public static java.util.Properties readFilelistToProperties(java.io.File input)
                                                     throws java.io.IOException
Read filelist to properties.

Parameters:
input - the input
Returns:
the properties
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

readFileToList

public static java.util.List<java.lang.String> readFileToList(java.io.File file)
                                                       throws java.io.IOException
Reads every line from the given File into a List and returns the List.

Parameters:
file - The file from where to read.
Returns:
The List with all lines from the File.
Throws:
java.io.IOException - When a io-problem occurs.

readFileToList

public static java.util.List<java.lang.String> readFileToList(java.io.File file,
                                                              java.lang.String encoding)
                                                       throws java.io.IOException
Reads every line from the given File into a List and returns the List.

Parameters:
file - The file from where to read.
encoding - The encoding to read.
Returns:
The List with all lines from the File.
Throws:
java.io.IOException - When a io-problem occurs.

readLinesInList

public static java.util.List<java.lang.String> readLinesInList(java.io.File input,
                                                               java.lang.String encoding)
                                                        throws java.io.IOException
Reads every line from the File and puts them to the List.

Parameters:
input - The File from where the input comes.
encoding - The encoding from the file.
Returns:
The List with all lines from the file.
Throws:
java.io.IOException - When a io-problem occurs.

removeQuotesFromString

@Deprecated
public static java.lang.String removeQuotesFromString(java.lang.String s)
Deprecated. Use instead StringUtils.removeQuotesFromString(String).

Removes from the given String the first and the last character.

Parameters:
s - The String to handle.
Returns:
The String with the without the first and the last character.

sortData

public static java.lang.String[] sortData(java.io.File csvData,
                                          java.lang.String encoding)
                                   throws java.io.FileNotFoundException,
                                          java.io.IOException
Read an csv-file and puts them in a String-array.

Parameters:
csvData - The csv-file with the data.
encoding - The encoding to read.
Returns:
The data from the csv-file as a String-array.
Throws:
FileDoesNotExistException - When the File is not found.
java.io.IOException - When an io-error occurs.
java.io.FileNotFoundException

storeFilelistToProperties

public static void storeFilelistToProperties(java.io.File output,
                                             java.io.File input,
                                             java.lang.String comments)
                                      throws java.io.IOException
Stores a komma seperated file to a properties object. As key is the number from the counter.

Parameters:
output - the output
input - the input
comments - the comments
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

writeLines

public static void writeLines(java.io.File output,
                              java.util.Set<java.lang.String> values,
                              java.lang.String encoding)
                       throws java.io.IOException
Writes the toString() value of each item in a collection to the specified File line by line. The default VM encoding and the default line ending will be used.

Parameters:
output - The File where the values to save.
values - The Set with the values to put into the file.
encoding - The encoding from the file.
Throws:
java.io.IOException - When a io-problem occurs.

writeLinesToFile

public static void writeLinesToFile(java.util.Collection<java.lang.String> collection,
                                    java.io.File output,
                                    java.lang.String encoding)
Writes all the String-object in the collection into the given file.

Parameters:
collection - The collection with the String-object.
output - The file where the String-object will be writing.
encoding - The encoding from the file.


Copyright © 2010. All Rights Reserved.