|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.jmatchparser.util.ExpectReader
public class ExpectReader
A fairly simple reader class, that can "expect" constant text and regular expressions, while still leaving full control to the programmer. This parser is fully deterministic; therefore, using it on more complex documents can be quite frustrating. Basically, this is what I used before I wrote JMatchParser. It is included because I still have old projects using it, and because it might be useful for simple projects.
Constructor Summary | |
---|---|
ExpectReader(BufferedReader br)
Create a new expect reader reading from the given BufferedReader . |
|
ExpectReader(InputStream in,
String charsetName)
Create a new expect reader reading from the given InputStream . |
|
ExpectReader(Reader r)
Create a new expect reader reading from the given Reader . |
Method Summary | |
---|---|
void |
close()
Close the underlying reader. |
void |
ensureEndOfFile()
Ensure that the end of file has been reached. |
static List<Matcher> |
ensureMultiRegexMatch(String actual,
Pattern pattern,
Pattern terminalPattern,
int restGroup)
Perform a multi regex match. |
static List<Matcher> |
ensureMultiRegexMatch(String actual,
String regex,
String terminalRegex,
int restGroup)
Perform a multi regex match. |
String |
ensureReadLine()
Read a line from the reader, and return it. |
String |
ensureReadTrimmedLine()
Read a line like ensureReadLine() , but trim the response and
skip empty lines. |
static Matcher |
ensureRegexMatch(String actual,
Pattern pattern)
Ensure that a string matches a pattern and returns a Matcher . |
static Matcher |
ensureRegexMatch(String actual,
String pattern)
Ensure that a string matches a pattern and returns a Matcher . |
static void |
ensureStringMatch(String actual,
String expected)
Ensure that two strings are the same. |
void |
expect(String... lines)
Expect one ore more lines. |
void |
expectLine(String line)
Expect a line. |
Matcher |
expectRegex(Pattern pattern)
Expect a line that matches a regex. |
Matcher |
expectRegex(String regex)
Expect a line that matches a regex. |
void |
expectTrimmed(String... lines)
Expect one ore more trimmed lines. |
void |
expectTrimmedLine(String line)
Expect a trimmed. |
Matcher |
expectTrimmedRegex(Pattern pattern)
Expect a trimmed line that matches a regex. |
Matcher |
expectTrimmedRegex(String regex)
Expect a trimmed line that matches a regex. |
BufferedReader |
getReader()
Return the reader used. |
String |
readLine()
Read a line. |
static Matcher |
regexMatch(String actual,
Pattern pattern)
Try to match a string against pattern and returns a Matcher or
null . |
static Matcher |
regexMatch(String actual,
String pattern)
Try to match a string against pattern and returns a Matcher or
null . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ExpectReader(BufferedReader br)
BufferedReader
.
public ExpectReader(Reader r)
Reader
.
public ExpectReader(InputStream in, String charsetName) throws UnsupportedEncodingException
InputStream
.
UnsupportedEncodingException
Method Detail |
---|
public BufferedReader getReader()
public String ensureReadLine() throws IOException
IOException
public String ensureReadTrimmedLine() throws IOException
ensureReadLine()
, but trim the response and
skip empty lines.
IOException
public String readLine() throws IOException
IOException
BufferedReader.readLine()
public void ensureEndOfFile() throws IOException
IOException
public void close() throws IOException
IOException
public void expect(String... lines) throws IOException
IOException
expectLine(String)
public void expectTrimmed(String... lines) throws IOException
IOException
expectTrimmedLine(String)
public void expectLine(String line) throws IOException
Reader
's next line does not match the line
given, an exception is thrown.
IOException
public void expectTrimmedLine(String line) throws IOException
Reader
's next line does not match the
line given, after trimming, an exception is thrown.
For symmetry reasons, calling this method with an empty string is a
no-op.
IOException
public static void ensureStringMatch(String actual, String expected)
actual
- The actual stringexpected
- The expected stringpublic Matcher expectRegex(String regex) throws IOException
Matcher
to read the groups
is returned.
IOException
public Matcher expectRegex(Pattern pattern) throws IOException
Matcher
to read the groups
is returned.
IOException
public Matcher expectTrimmedRegex(String regex) throws IOException
Matcher
to read the
groups is returned.
IOException
ensureReadTrimmedLine()
public Matcher expectTrimmedRegex(Pattern pattern) throws IOException
Matcher
to read the
groups is returned.
IOException
ensureReadTrimmedLine()
public static Matcher ensureRegexMatch(String actual, String pattern)
Matcher
.
actual
- The actual stringpattern
- The patternpublic static Matcher ensureRegexMatch(String actual, Pattern pattern)
Matcher
.
actual
- The actual stringpattern
- The patternpublic static Matcher regexMatch(String actual, String pattern)
Matcher
or
null
.
actual
- The actual stringpattern
- The patternpublic static Matcher regexMatch(String actual, Pattern pattern)
Matcher
or
null
.
actual
- The actual stringpattern
- The patternpublic static List<Matcher> ensureMultiRegexMatch(String actual, String regex, String terminalRegex, int restGroup)
ensureMultiRegexMatch(String, Pattern, Pattern, int)
public static List<Matcher> ensureMultiRegexMatch(String actual, Pattern pattern, Pattern terminalPattern, int restGroup)
If terminalPattern is non-null
: Match actual against the
terminal pattern. If it matches, the match is finished. If not, it is
matched against the pattern and added to the result list (non-match is an
error). The restGroup'th group of the matcher is then used as the actual
value for the next round.
If terminalPattern is null
: Terminate when it does not match
any longer. Rest as above.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |