|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.bm.utils.csv.CSVLexer
public class CSVLexer
Read files in comma separated value format.
Field Summary | |
---|---|
static int |
AFTER
|
static int |
BEFORE
lexical states |
static int |
COMMENT
|
static int |
YYEOF
This character denotes the end of file |
static int |
YYINITIAL
|
Constructor Summary | |
---|---|
CSVLexer(java.io.InputStream in)
Creates a new scanner. |
|
CSVLexer(java.io.Reader in)
Creates a new scanner There is also a java.io.InputStream version of this constructor. |
Method Summary | |
---|---|
void |
changeDelimiter(char newDelim)
Change this Lexer so that it uses a new delimiter. |
void |
changeQuote(char newQuote)
Change this Lexer so that it uses a new character for quoting. |
int |
getLineNumber()
Get the line number that the last token came from. |
java.lang.String |
getNextToken()
Resumes scanning until the next regular expression is matched, the end of input is encountered or an I/O-Error occurs. |
static void |
main(java.lang.String[] args)
Prints out tokens and line numbers from a file or System.in. |
void |
setCommentStart(java.lang.String commentDelims)
Set the characters that indicate a comment at the beginning of the line. |
void |
setEscapes(java.lang.String escapes,
java.lang.String replacements)
Specify escape sequences and their replacements. |
void |
yybegin(int newState)
Enters a new lexical state |
char |
yycharat(int pos)
Returns the character at position pos from the matched text. |
void |
yyclose()
Closes the input stream. |
int |
yylength()
Returns the length of the matched text region. |
void |
yypushback(int number)
Pushes the specified amount of characters back into the input stream. |
void |
yyreset(java.io.Reader reader)
Resets the scanner to read from a new input stream. |
int |
yystate()
Returns the current lexical state. |
java.lang.String |
yytext()
Returns the text matched by the current regular expression. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int YYEOF
public static final int BEFORE
public static final int YYINITIAL
public static final int COMMENT
public static final int AFTER
Constructor Detail |
---|
public CSVLexer(java.io.Reader in)
in
- the java.io.Reader to read input from.public CSVLexer(java.io.InputStream in)
in
- the java.io.Inputstream to read input from.Method Detail |
---|
public static void main(java.lang.String[] args)
args
- program arguments, of which the first is a filenamepublic void changeDelimiter(char newDelim) throws BadDelimiterException
The initial character is a comma, the delimiter cannot be changed to a quote or other character that has special meaning in CSV.
newDelim
- delimiter to which to switch.
BadDelimiterException
- if the character cannot be used as a delimiter.public void changeQuote(char newQuote) throws BadQuoteException
The initial character is a double quote ("), the delimiter cannot be changed to a comma or other character that has special meaning in CSV.
newQuote
- character to use for quoting.
BadQuoteException
- if the character cannot be used as a quote.public void setEscapes(java.lang.String escapes, java.lang.String replacements)
setEscapes("nrtf", "\n\r\t\f");
escapes
- a list of characters that will represent escape sequences.replacements
- the list of repacement characters for those escape sequences.public void setCommentStart(java.lang.String commentDelims)
# Comment ; Another Comment ! Yet another commentBy default there are no comments in CVS files. Commas and quotes may not be used to indicate comment lines.
commentDelims
- list of characters a comment line may start with.public int getLineNumber()
New line breaks that occur in the middle of a token are not counted in the line number count.
If no tokens have been returned, the line number is undefined.
public final void yyclose() throws java.io.IOException
java.io.IOException
public final void yyreset(java.io.Reader reader)
reader
- the new input streampublic final int yystate()
public final void yybegin(int newState)
newState
- the new lexical statepublic final java.lang.String yytext()
public final char yycharat(int pos)
pos
- the position of the character to fetch. A value from 0 to
yylength()-1.
public final int yylength()
public void yypushback(int number)
number
- the number of characters to be read again. This number must
not be greater than yylength()!public java.lang.String getNextToken() throws java.io.IOException
java.io.IOException
- if any I/O-Error occurs
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |