Class LineParser
java.lang.Object
com.northconcepts.datapipeline.core.LineParser
- All Implemented Interfaces:
IParser
An
IParser that reads its input one line at a time; lookahead and matching only see the current line until
cacheNextLine() moves to the next one.-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionLineParser(Reader reader, char[][] lineSeparators) Creates a parser that ends lines at the given separators, checked in array order, or likeBufferedReader.readLine()if they are null.LineParser(String text, char[][] lineSeparators) Creates a parser that ends lines at the given separators, checked in array order, or likeBufferedReader.readLine()if they are null. -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidclose()voidconsume()voidconsume(int count) voidvoidconsumeWhitespace(char[] exception) Skips whitespace at the current position, stopping where the given string (such as a field separator) begins.voidconsumeWhitespace(int exception) Skips spaces and tabs at the current position, stopping early at the given character.voidconsumeWhitespace(CharSequence exception) Skips whitespace at the current position, stopping where the given string (such as a field separator) begins.Wraps the exception in aDataExceptionand adds the parser's buffer and position as properties.longReturns the number of characters consumed so far (within the current line forLineParser).char[]longgetLine()Returns the 0-based number of the current line or -1 before the first line is read.Returns the current line's text, without its separator, or null before the first line is read.Returns the unconsumed rest of the current line, an empty string if it is fully consumed, or null before the first line is read.voidmatch(char expectedChar) Consumes the next character, throwing aDataExceptionif it is not the expected one.voidmatch(char[] expectedString) Consumes the expected string, throwing aDataExceptionat the first character that differs.voidConsumes the expected string, throwing aDataExceptionprefixed withfailureMessageat the first character that differs.voidConsumes the next character, throwing aDataExceptionprefixed withfailureMessageif it is not the expected one.voidmatch(CharSequence expectedString) Consumes the expected string, throwing aDataExceptionat the first character that differs.voidmatch(CharSequence expectedString, String failureMessage) Consumes the expected string, throwing aDataExceptionprefixed withfailureMessageat the first character that differs.matchUntil(char terminatingChar) Consumes and returns the text before the terminating character, then consumes the terminator; throws aDataExceptionif the input ends first.matchUntil(char terminatingChar, String failureMessage) Consumes and returns the text before the terminating character, then consumes the terminator; throws aDataExceptionprefixed withfailureMessageif the input ends first.Consumes and returns all remaining characters (of the current line forLineParser).voidnextLine()Moves to the next line, throwing aDataExceptionif the input has ended.voidMoves to the next line, throwing aDataExceptionprefixed withfailureMessageif the input has ended.intpeek(int index) Returns the character at the given 0-based offset ahead without consuming it, orIParser.EOFpast the end of the input.peekSequence(int offset, int length) Returns up tolengthcharacters starting at the given lookahead offset without consuming them; fewer if the input ends first.booleanpeekString(char[] lookahead) Indicates if the upcoming characters match the given string, without consuming them.booleanpeekString(CharSequence lookahead) Indicates if the upcoming characters match the given string, without consuming them.intpeekStringArray(char[][] lookahead) Returns the index of the first string that matches the upcoming characters or -1 if none do, without consuming them.intpeekStringArray(char[][] lookahead, int offset) Returns the index of the first string that matches the characters at the given lookahead offset or -1 if none do.intpeekStringArray(CharSequence... lookahead) Returns the index of the first string that matches the upcoming characters or -1 if none do, without consuming them.intpeekStringArray(CharSequence[] lookahead, int offset) Returns the index of the first string that matches the characters at the given lookahead offset or -1 if none do.booleanpeekStringOffset(char[] lookahead, int offset) Indicates if the characters starting at the given lookahead offset match the given string, without consuming them.booleanpeekStringOffset(CharSequence lookahead, int offset) Indicates if the characters starting at the given lookahead offset match the given string, without consuming them.intpeekWhitespaceLength(int index) Returns the number of consecutive whitespace characters starting at the given 0-based lookahead offset.intpop()Consumes and returns the next character, orIParser.EOFat the end of the input.booleanready()setLineSeparators(char[][] lineSeparators) Sets the separators that end a line, checked in array order; null ends lines likeBufferedReader.readLine().toString()
-
Constructor Details
-
LineParser
Creates a parser that ends lines at the given separators, checked in array order, or likeBufferedReader.readLine()if they are null. -
LineParser
Creates a parser that ends lines at the given separators, checked in array order, or likeBufferedReader.readLine()if they are null.
-
-
Method Details
-
exception
Description copied from interface:IParserWraps the exception in aDataExceptionand adds the parser's buffer and position as properties. -
setLineSeparators
Sets the separators that end a line, checked in array order; null ends lines likeBufferedReader.readLine(). -
getLastLineSeparator
public char[] getLastLineSeparator() -
cacheNextLine
public boolean cacheNextLine() -
ready
- Specified by:
readyin interfaceIParser- Throws:
IOException
-
getLine
public long getLine()Returns the 0-based number of the current line or -1 before the first line is read. -
getColumn
public long getColumn()Description copied from interface:IParserReturns the number of characters consumed so far (within the current line forLineParser). -
getLineText
Returns the current line's text, without its separator, or null before the first line is read. -
getRemainingLineText
Returns the unconsumed rest of the current line, an empty string if it is fully consumed, or null before the first line is read. -
peek
public int peek(int index) Description copied from interface:IParserReturns the character at the given 0-based offset ahead without consuming it, orIParser.EOFpast the end of the input. -
peekWhitespaceLength
public int peekWhitespaceLength(int index) Description copied from interface:IParserReturns the number of consecutive whitespace characters starting at the given 0-based lookahead offset.- Specified by:
peekWhitespaceLengthin interfaceIParser
-
peekSequence
Description copied from interface:IParserReturns up tolengthcharacters starting at the given lookahead offset without consuming them; fewer if the input ends first.- Specified by:
peekSequencein interfaceIParser
-
peekString
Description copied from interface:IParserIndicates if the upcoming characters match the given string, without consuming them.- Specified by:
peekStringin interfaceIParser
-
peekString
public boolean peekString(char[] lookahead) Description copied from interface:IParserIndicates if the upcoming characters match the given string, without consuming them.- Specified by:
peekStringin interfaceIParser
-
peekStringOffset
Description copied from interface:IParserIndicates if the characters starting at the given lookahead offset match the given string, without consuming them.- Specified by:
peekStringOffsetin interfaceIParser
-
peekStringOffset
public boolean peekStringOffset(char[] lookahead, int offset) Description copied from interface:IParserIndicates if the characters starting at the given lookahead offset match the given string, without consuming them.- Specified by:
peekStringOffsetin interfaceIParser
-
peekStringArray
Description copied from interface:IParserReturns the index of the first string that matches the upcoming characters or -1 if none do, without consuming them.- Specified by:
peekStringArrayin interfaceIParser
-
peekStringArray
Description copied from interface:IParserReturns the index of the first string that matches the characters at the given lookahead offset or -1 if none do.- Specified by:
peekStringArrayin interfaceIParser
-
peekStringArray
public int peekStringArray(char[][] lookahead) Description copied from interface:IParserReturns the index of the first string that matches the upcoming characters or -1 if none do, without consuming them.- Specified by:
peekStringArrayin interfaceIParser
-
peekStringArray
public int peekStringArray(char[][] lookahead, int offset) Description copied from interface:IParserReturns the index of the first string that matches the characters at the given lookahead offset or -1 if none do.- Specified by:
peekStringArrayin interfaceIParser
-
pop
public int pop()Description copied from interface:IParserConsumes and returns the next character, orIParser.EOFat the end of the input. -
nextLine
public void nextLine()Moves to the next line, throwing aDataExceptionif the input has ended. -
nextLine
Moves to the next line, throwing aDataExceptionprefixed withfailureMessageif the input has ended. -
match
Description copied from interface:IParserConsumes the next character, throwing aDataExceptionprefixed withfailureMessageif it is not the expected one. -
match
public void match(char expectedChar) Description copied from interface:IParserConsumes the next character, throwing aDataExceptionif it is not the expected one. -
match
Description copied from interface:IParserConsumes the expected string, throwing aDataExceptionprefixed withfailureMessageat the first character that differs. -
match
Description copied from interface:IParserConsumes the expected string, throwing aDataExceptionprefixed withfailureMessageat the first character that differs. -
match
Description copied from interface:IParserConsumes the expected string, throwing aDataExceptionat the first character that differs. -
match
public void match(char[] expectedString) Description copied from interface:IParserConsumes the expected string, throwing aDataExceptionat the first character that differs. -
matchUntil
Description copied from interface:IParserConsumes and returns the text before the terminating character, then consumes the terminator; throws aDataExceptionif the input ends first.- Specified by:
matchUntilin interfaceIParser
-
matchUntil
Description copied from interface:IParserConsumes and returns the text before the terminating character, then consumes the terminator; throws aDataExceptionprefixed withfailureMessageif the input ends first.- Specified by:
matchUntilin interfaceIParser
-
matchUntilEof
Description copied from interface:IParserConsumes and returns all remaining characters (of the current line forLineParser).- Specified by:
matchUntilEofin interfaceIParser
-
consume
public void consume() -
consume
public void consume(int count) -
consumeWhitespace
public void consumeWhitespace()- Specified by:
consumeWhitespacein interfaceIParser
-
consumeWhitespace
public void consumeWhitespace(int exception) Description copied from interface:IParserSkips spaces and tabs at the current position, stopping early at the given character.- Specified by:
consumeWhitespacein interfaceIParser
-
consumeWhitespace
Description copied from interface:IParserSkips whitespace at the current position, stopping where the given string (such as a field separator) begins.- Specified by:
consumeWhitespacein interfaceIParser
-
consumeWhitespace
public void consumeWhitespace(char[] exception) Description copied from interface:IParserSkips whitespace at the current position, stopping where the given string (such as a field separator) begins.- Specified by:
consumeWhitespacein interfaceIParser
-
close
public void close() -
toString
-