|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectinfo.fingo.csv.CSVParser
public class CSVParser
Class used to parse CSV (comma separated values) files. The first line of the file has to contain column headers (key values) and subsequent lines have to contain data.
| Field Summary | |
|---|---|
static java.lang.String |
DEFAULT_CHARSET
The default charset for parsed data |
static int |
TYPE_ANY
Field type: any type = 0 |
static int |
TYPE_BOOLEAN
Field type: boolean = 4 |
static int |
TYPE_DATE
Field type: andate = 5 |
static int |
TYPE_EMAIL
Field type: email = 6 |
static int |
TYPE_ENUMERATION
Field type: enumeration = 7 |
static int |
TYPE_INTEGER
Field type: any integer = 2 |
static int |
TYPE_NUMERIC
Field type: numeric = 3 |
static int |
TYPE_STRING
Field type: string = 1 |
| Constructor Summary | |
|---|---|
CSVParser()
Default constructor. |
|
CSVParser(java.lang.String charset)
Creates new parser with the given charset. |
|
| Method Summary | |
|---|---|
void |
defineField(java.lang.String key,
int type,
boolean required)
Defines field in CSV file for validation. |
void |
defineFieldBoolean(java.lang.String key,
boolean required)
Defines field of type Boolean in CSV file for validation. |
void |
defineFieldDate(java.lang.String key,
boolean required,
java.util.Date minValue,
java.util.Date maxValue)
Define field of type Date in CSV file for validation. |
void |
defineFieldEmail(java.lang.String key,
boolean required,
java.lang.Integer maxLength)
Define field of type Email in CSV file for validation. |
void |
defineFieldEnumeration(java.lang.String key,
boolean required,
java.lang.Object[] enumeration)
Define field of type Enumeration in CSV file for validation. |
void |
defineFieldInteger(java.lang.String key,
boolean required,
java.lang.Integer minValue,
java.lang.Integer maxValue)
Defines field of type Integer in CSV file for validation. |
void |
defineFieldNumeric(java.lang.String key,
boolean required,
java.lang.Number minValue,
java.lang.Number maxValue)
Defines field of type Numeric in CSV file for validation. |
void |
defineFieldString(java.lang.String key,
boolean required,
java.lang.Integer minLength,
java.lang.Integer maxLength)
Defines field of type String in CSV file for validation. |
java.util.HashMap<java.lang.String,java.lang.String>[] |
parse(java.io.InputStream is,
char delim)
Function for csv file parsing. |
java.util.HashMap<java.lang.String,java.lang.String>[] |
parse(java.lang.String path,
char delim)
Function for csv file parsing. |
CSVStatus |
validate()
Validate data read by parse(). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String DEFAULT_CHARSET
public static final int TYPE_ANY
public static final int TYPE_STRING
public static final int TYPE_INTEGER
public static final int TYPE_NUMERIC
public static final int TYPE_BOOLEAN
public static final int TYPE_DATE
public static final int TYPE_EMAIL
public static final int TYPE_ENUMERATION
| Constructor Detail |
|---|
public CSVParser()
public CSVParser(java.lang.String charset)
charset - the charset to be used for parsing data| Method Detail |
|---|
public void defineField(java.lang.String key,
int type,
boolean required)
key - field codetype - field type, one of TYPE_* constantsrequired - field is mandatory if set
public void defineFieldString(java.lang.String key,
boolean required,
java.lang.Integer minLength,
java.lang.Integer maxLength)
key - field coderequired - field is mandatory if setminLength - minimum length of string or nullmaxLength - maximum length of string or null
public void defineFieldInteger(java.lang.String key,
boolean required,
java.lang.Integer minValue,
java.lang.Integer maxValue)
key - field coderequired - field is mandatory if setminValue - minimum value or nullmaxValue - maximum value or null
public void defineFieldNumeric(java.lang.String key,
boolean required,
java.lang.Number minValue,
java.lang.Number maxValue)
key - field coderequired - field is mandatory if setminValue - minimum value or nullmaxValue - maximum value or null
public void defineFieldBoolean(java.lang.String key,
boolean required)
key - field coderequired - field is mandatory if set
public void defineFieldDate(java.lang.String key,
boolean required,
java.util.Date minValue,
java.util.Date maxValue)
key - field coderequired - field is mandatory if setminValue - minimum value or nullmaxValue - maximum value or null
public void defineFieldEmail(java.lang.String key,
boolean required,
java.lang.Integer maxLength)
key - field coderequired - field is mandatory if setmaxLength - maximum length pf string
public void defineFieldEnumeration(java.lang.String key,
boolean required,
java.lang.Object[] enumeration)
key - field coderequired - field is mandatory if setenumeration - Array of Objects containing enumerated values
public java.util.HashMap<java.lang.String,java.lang.String>[] parse(java.lang.String path,
char delim)
throws java.io.FileNotFoundException,
java.io.IOException,
CSVException
path - full input file name and pathdelim - tokens delimiter
java.io.FileNotFoundException
java.io.IOException
CSVException
public java.util.HashMap<java.lang.String,java.lang.String>[] parse(java.io.InputStream is,
char delim)
throws java.io.IOException,
CSVException
is - input stream to parsedelim - char containing tokens delimiter
java.io.IOException
CSVException
public CSVStatus validate()
throws CSVException
parse(). Use defineField() to prepare validation
CSVException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||