|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.google.api.ads.common.lib.utils.CsvFiles
public final class CsvFiles
A utility class for processing and handling CSV files.
| Method Summary | |
|---|---|
static List<String[]> |
getCsvDataArray(Reader csvReader,
boolean headerPresent)
Returns a List<String[]> that contains all rows of the CSV file. |
static List<String[]> |
getCsvDataArray(String fileName,
boolean headerPresent)
Returns a List<String[]> that contains all rows of the CSV file. |
static List<String> |
getCsvDataByColumn(String fileName,
int column,
boolean headerPresent)
Returns a List<String> representing a single 0-indexed column. |
static List<Map<String,String>> |
getCsvDataListMap(String fileName,
boolean headerPresent)
Returns a List<Map<String, String>> that contains all rows with
a field mapping defined by the header. |
static Map<String,String> |
getCsvDataMap(String fileName,
boolean headerPresent)
Returns a Map<String, String> mapping of the first column to the
second column. |
static Map<String,String> |
getCsvDataMap(String fileName,
int key,
int value,
boolean headerPresent)
Returns a Map<String, String> mapping of the column designated by
key to the column designated by value. |
static Map<String,String[]> |
getCsvDataMapArray(String fileName,
boolean headerPresent)
Returns a Map<String, String[]> mapping of the first column to an
array of the rest of the columns. |
static void |
writeCsv(List<String[]> csvData,
String fileName)
Writes the CSV data located in csvData to the file located at
fileName. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static Map<String,String> getCsvDataMap(String fileName,
int key,
int value,
boolean headerPresent)
throws IOException
Map<String, String> mapping of the column designated by
key to the column designated by value. This method also
ignores all columns other than the columns specified by key and
value.
fileName - the CSV file to loadkey - the 0-indexed column number to map to the key of the returned
data mapvalue - the column number to map to the value of the returned data
mapheaderPresent - true if the fist line is the header
Map<String, String> mapping of the columns specified by
key and value
IOException - if there was an error while reading the file
IllegalArgumentException - if CSV file does not have the
columns specified by key or value
public static Map<String,String> getCsvDataMap(String fileName,
boolean headerPresent)
throws IOException
Map<String, String> mapping of the first column to the
second column. This method also ignores all columns other than the first
two.
fileName - the CSV file to loadheaderPresent - true if the fist line is the header
Map<String, String> mapping of the first to the second
column
IOException - if there was an exception reading the file
IllegalArgumentException - if CSV file has fewer than two
columns
public static Map<String,String[]> getCsvDataMapArray(String fileName,
boolean headerPresent)
throws IOException
Map<String, String[]> mapping of the first column to an
array of the rest of the columns.
fileName - the CSV file to loadheaderPresent - true if the fist line is the header
Map<String, String[]> mapping of the first column to an
array of the rest of the columns
IllegalArgumentException - if there is fewer than 2 columns in
the CSV
IOException - if there was an exception reading the file
public static List<Map<String,String>> getCsvDataListMap(String fileName,
boolean headerPresent)
throws IOException
List<Map<String, String>> that contains all rows with
a field mapping defined by the header. If no header is present,
then each field is the 0-indexed column number.
fileName - the CSV file to loadheaderPresent - true if the first line is the header
List<Map<String, String>> that contains all rows with
with a field mapping defined by the header if present.
IOException - if there was an exception reading the file
public static List<String> getCsvDataByColumn(String fileName,
int column,
boolean headerPresent)
throws IOException
List<String> representing a single 0-indexed column.
fileName - the CSV file to loadcolumn - the 0-indexed column to returnheaderPresent - true if the first line is the header
List<String> representing a single column
IOException - if there was an exception reading the file
IllegalArgumentException - if the column index does not exist in
the CSV
public static List<String[]> getCsvDataArray(String fileName,
boolean headerPresent)
throws IOException
List<String[]> that contains all rows of the CSV file.
The header will be removed, if present.
fileName - the CSV file to loadheaderPresent - true if the first line is the header
List<String[]> that contains all rows of the CSV file
IOException - if there was an exception reading the file
public static List<String[]> getCsvDataArray(Reader csvReader,
boolean headerPresent)
throws IOException
List<String[]> that contains all rows of the CSV file.
The header will be removed, if present.
csvReader - reader used to read the csvheaderPresent - true if the first line is the header
List<String[]> that contains all rows of the CSV file
IOException - if there was an exception reading the file
public static void writeCsv(List<String[]> csvData,
String fileName)
throws IOException
csvData to the file located at
fileName.
csvData - the CSV data including the headerfileName - the file to write the CSV data to
IOException - if there was an error writing to the file
IllegalArgumentException - if csvData == null
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||