Package com.globalmentor.io
Class ReaderParser
- java.lang.Object
-
- com.globalmentor.io.ReaderParser
-
public class ReaderParser extends java.lang.Object
Parsing methods that work on aReader
. The reader must support marking.This parser supports several general operations:
- check
- Checks the parsed content, throwing an exception if the content does not match that expected. The content is consumed. Implies that an exception will be
thrown if the end of the content is reached. Semantically a "check" operation is equivalent to a "confirm" operation that throws an exception if the result
is
false
. - confirm
- Compares the content and returns whether it matches that expected. If the content matches, it is consumed. If the content does not match, it is not consumed. No exception is thrown based upon the match.
- pass
- Skips content until some delimiter is encountered. The reached content is discarded. By default no exception is thrown if the end of the content is reached, unless the method indicates that reaching the delimiter is required. The semantics of "reach" is the same as "read past", discarding content.
- reach
- Skips content until some delimiter is encountered. The reached content is not consumed. By default no exception is thrown if the end of the content is reached, unless the method indicates that reaching the delimiter is required. The semantics of "reach" is the same as "read until", discarding content.
- read
- Reads content; either "while" some content is encountered, or "until" some content is encountered (which will not be read), or "past" some content (which will be read). By default no exception is thrown if the end of the content is reached, unless the method indicates that reaching the delimiter is required.
- skip
- Skips and discards content. No exception is thrown if the end of the content is reached. The semantics of "skip" is the same as "read while", discarding content.
- Author:
- Garret Wilson
- See Also:
Reader.markSupported()
-
-
Field Summary
Fields Modifier and Type Field Description static int
MINIMUM_MARK
The minimum number of characters to mark in a reader.
-
Constructor Summary
Constructors Constructor Description ReaderParser()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static char
check(java.io.Reader reader, char character)
Checks that the current character matches a specific character and advances to the next character.static char
check(java.io.Reader reader, Characters characters)
Checks that the current character matches a given set of characters and advances to the next character.static java.lang.CharSequence
check(java.io.Reader reader, java.lang.CharSequence match)
Checks that the current and subsequent characters matches a specified character sequence.static java.lang.String
checkCount(java.io.Reader reader, Characters characters, int count)
Checks that the a certain number of characters matches a given set of characters and advances to the next character.static java.lang.StringBuilder
checkCount(java.io.Reader reader, Characters characters, int count, java.lang.StringBuilder stringBuilder)
Checks that the a certain number of characters matches a given set of characters and advances to the next character.static void
checkParseIO(java.io.Reader reader, boolean test, java.lang.String description, java.lang.Object... arguments)
Checks for a parsing condition and, if the test did not pass, throws aParseIOException
.static void
checkReaderEnd(java.io.Reader reader)
Checks that reader has no more data.static int
checkReaderNotEnd(java.io.Reader reader, int c)
Checks that a read character does not represent the end of the reader's data.static boolean
confirm(java.io.Reader reader, char character)
Reads a character and, if a character does not match the given character, resets the reader as if the character were not read.static boolean
confirm(java.io.Reader reader, Characters characters)
Reads a character and, if a character does not match the given set of characters, resets the reader as if the character were not read.static boolean
confirm(java.io.Reader reader, java.lang.CharSequence charSequence)
Reads a string and, if the string does not match the given character sequence, resets the reader as if the string was not read.protected static java.lang.StringBuilder
consumeUntil(java.io.Reader reader, char untilCharacter, boolean isEndError, java.lang.StringBuilder stringBuilder, boolean includeReached)
Reads all characters in a reader until one of the given characters is reached.protected static java.lang.StringBuilder
consumeUntil(java.io.Reader reader, Characters untilCharacters, boolean isEndError, java.lang.StringBuilder stringBuilder, boolean includeReached)
Reads all characters in a reader until one of the given characters is reached.protected static java.lang.StringBuilder
consumeUntil(java.io.Reader reader, Characters untilCharacters, char untilCharacter, boolean isEndError, java.lang.StringBuilder stringBuilder, boolean includeReached)
Reads all characters in a reader until one of the given characters is reached.static void
pass(java.io.Reader reader, char character)
Skips all characters in a reader until the given delimiter is passed or the end is reached.static void
pass(java.io.Reader reader, Characters characters)
Skips all characters in a reader until one of the given characters or the end is reached.static void
passRequired(java.io.Reader reader, char character)
Skips all characters in a reader until the given delimiter is passed, throwing an exception if the end of the reader has been reached.static void
passRequired(java.io.Reader reader, Characters characters)
Skips all characters in a reader until one of the given characters is reached, throwing an exception if the end of the reader has been reached.static int
peek(java.io.Reader reader)
Reads a character and, if a character was read (i.e.static char
peekRequired(java.io.Reader reader)
Reads a character and and resets the reader as if the character were not read, throwing an exception if the end of the reader has been reached.static void
reach(java.io.Reader reader, char character)
Skips all characters in a reader until the given delimiter is passed or the end is reached.static void
reach(java.io.Reader reader, Characters characters)
Skips all characters in a reader until one of the given characters or the end is reached.static void
reachRequired(java.io.Reader reader, char character)
Skips all characters in a reader until the given delimiter is passed, throwing an exception if the end of the reader has been reached.static void
reachRequired(java.io.Reader reader, Characters characters)
Skips all characters in a reader until one of the given characters is reached, throwing an exception if the end of the reader has been reached.static java.lang.String
readEnclosedRequired(java.io.Reader reader, char startDelimiter, char endDelimiter)
Reads text from a reader that has certain required beginning and ending delimiter characters.static java.lang.String
readPast(java.io.Reader reader, Characters characters)
Reads all characters in a reader until one of the given characters or the end is reached.static java.lang.String
readPastRequired(java.io.Reader reader, Characters characters)
Reads all characters in a reader until one of the given characters.static char
readRequired(java.io.Reader reader)
Reads a character, throwing an error if the end of the reader was reached.static java.lang.String
readRequiredCount(java.io.Reader reader, int count)
Reads a given number of characters, throwing an error if the end of the reader was reached.static java.lang.String
readRequiredCount(java.io.Reader reader, Characters characters, int count)
Reads a given number of characters, throwing an error if the end of the reader was reached or if a character in the string does not match one of the given characters.static java.lang.String
readRequiredMinimumCount(java.io.Reader reader, Characters characters, int minimumCount)
Reads at least a minimum number of characters in a reader that appear in a set of characters.static java.lang.StringBuilder
readRequiredMinimumCount(java.io.Reader reader, Characters characters, int minimumCount, java.lang.StringBuilder stringBuilder)
Reads at least a minimum number of characters in a reader that appear in a set of characters.static java.lang.String
readUntil(java.io.Reader reader, Characters characters)
Reads all characters in a reader until one of the given characters or the end is reached.static java.lang.String
readUntilRequired(java.io.Reader reader, char character)
Reads all characters in a reader until the given delimiter is reached, throwing an exception if the end of the reader has been reached.static java.lang.String
readUntilRequired(java.io.Reader reader, Characters characters)
Reads all characters in a reader until one of the given characters is reached, throwing an exception if the end of the reader has been reached.static java.lang.String
readWhile(java.io.Reader reader, Characters characters)
Reads all characters in a reader that appear within a given set of characters.static java.lang.StringBuilder
readWhile(java.io.Reader reader, Characters characters, java.lang.StringBuilder stringBuilder)
Reads all characters in a reader that appear within a given set of characters and collects them in a given string builder.static int
skip(java.io.Reader reader, Characters characters)
Skips over characters in a reader that appear within a given set of characters.
-
-
-
Field Detail
-
MINIMUM_MARK
public static final int MINIMUM_MARK
The minimum number of characters to mark in a reader. This value is guaranteed to be at least1
for marking a single character. If fewer than the minimum characters are marked, an ancient bug in theLineNumberReader
could results in anIOException
for "mark invalid" if aCRLF
happens to straddle the end the buffer.
-
-
Method Detail
-
checkParseIO
public static void checkParseIO(@Nonnull java.io.Reader reader, boolean test, @Nullable java.lang.String description, java.lang.Object... arguments) throws ParseIOException
Checks for a parsing condition and, if the test did not pass, throws aParseIOException
.- Parameters:
reader
- The reader the contents of which to be parsed.test
- The result of the test.description
- A description of the test to be used when generating an exception, optionally formatted with arguments, ornull
for no description.arguments
- The arguments to be applied when formatting, or an empty array if the message should not be formatted.- Throws:
java.lang.NullPointerException
- if the given arguments isnull
.ParseIOException
- if the given value isfalse
.ParseIOException
- if the description is an invalid pattern, or if an argument in the arguments array is not of the type expected by the format element(s) that use it.- See Also:
String.format(String, Object...)
-
checkReaderEnd
public static void checkReaderEnd(@Nonnull java.io.Reader reader) throws java.io.IOException, ParseUnexpectedDataException
Checks that reader has no more data.- Parameters:
reader
- The reader the contents of which to be parsed.- Throws:
java.lang.NullPointerException
- if the given reader isnull
.java.io.IOException
- if there is an error reading from the reader.ParseUnexpectedDataException
- if the reader is not at the end of data.
-
checkReaderNotEnd
public static int checkReaderNotEnd(@Nonnull java.io.Reader reader, int c) throws ParseEOFException
Checks that a read character does not represent the end of the reader's data.- Parameters:
reader
- The reader the contents of which to be parsed.c
- The character returned from a reader'sReader.read()
operation.- Returns:
- The given character.
- Throws:
java.lang.NullPointerException
- if the given reader isnull
.ParseEOFException
- if the given character represents the end of the reader's data.
-
check
public static char check(@Nonnull java.io.Reader reader, char character) throws java.io.IOException, ParseUnexpectedDataException
Checks that the current character matches a specific character and advances to the next character.- Parameters:
reader
- The reader the contents of which to be parsed.character
- The character against which which the current character should be checked.- Returns:
- The character returned the reader's
Reader.read()
operation. - Throws:
java.lang.NullPointerException
- if the given reader isnull
.java.io.IOException
- if there is an error reading from the reader.ParseUnexpectedDataException
- if the current character in the reader does not match the specified character.ParseEOFException
- if the reader has no more characters.- See Also:
confirm(Reader, char)
-
check
public static char check(@Nonnull java.io.Reader reader, @Nonnull Characters characters) throws java.io.IOException, ParseUnexpectedDataException
Checks that the current character matches a given set of characters and advances to the next character.- Parameters:
reader
- The reader the contents of which to be parsed.characters
- The characters to accept.- Returns:
- The character returned the reader's
Reader.read()
operation. - Throws:
java.lang.NullPointerException
- if the given reader and/or the given characters isnull
.java.io.IOException
- if there is an error reading from the reader.ParseUnexpectedDataException
- if the current character in the reader does not match one of the specified characters.ParseEOFException
- if the reader has no more characters.
-
checkCount
public static java.lang.String checkCount(@Nonnull java.io.Reader reader, @Nonnull Characters characters, int count) throws java.io.IOException, ParseUnexpectedDataException
Checks that the a certain number of characters matches a given set of characters and advances to the next character.- Parameters:
reader
- The reader the contents of which to be parsed.characters
- The characters to accept.count
- The number of characters to read.- Returns:
- A string containing the characters returned the reader's
Reader.read()
operation. - Throws:
java.lang.NullPointerException
- if the given reader and/or the given characters isnull
.java.io.IOException
- if there is an error reading from the reader.ParseUnexpectedDataException
- if one of the characters in the reader does not match one of the specified characters.ParseEOFException
- if the reader has no more characters.
-
checkCount
public static java.lang.StringBuilder checkCount(@Nonnull java.io.Reader reader, @Nonnull Characters characters, int count, @Nonnull java.lang.StringBuilder stringBuilder) throws java.io.IOException, ParseUnexpectedDataException
Checks that the a certain number of characters matches a given set of characters and advances to the next character.- Parameters:
reader
- The reader the contents of which to be parsed.characters
- The characters to accept.count
- The number of characters to read.stringBuilder
- The string builder to receive the characters read.- Returns:
- The given string builder with the added characters.
- Throws:
java.lang.NullPointerException
- if the given reader, characters, and/or string builder isnull
.java.io.IOException
- if there is an error reading from the reader.ParseUnexpectedDataException
- if one of the characters in the reader does not match one of the specified characters.ParseEOFException
- if the reader has no more characters.
-
check
public static java.lang.CharSequence check(@Nonnull java.io.Reader reader, @Nonnull java.lang.CharSequence match) throws java.io.IOException, ParseUnexpectedDataException
Checks that the current and subsequent characters matches a specified character sequence.- Parameters:
reader
- The reader the contents of which to be parsed.match
- The character sequence with which the current characters should be checked.- Returns:
- The character sequence that was checked.
- Throws:
java.lang.NullPointerException
- if the given reader and/or match character sequence isnull
.java.io.IOException
- if there is an error reading from the reader.ParseUnexpectedDataException
- if the current character in the reader does not match the specified character sequence.ParseEOFException
- if the reader has no more characters.
-
confirm
public static boolean confirm(@Nonnull java.io.Reader reader, char character) throws java.io.IOException
Reads a character and, if a character does not match the given character, resets the reader as if the character were not read.- Parameters:
reader
- The reader the contents of which to be parsed.character
- The expected character.- Returns:
true
if the given character was read, orfalse
if the next character is not the expected character and was therefore replaced if the end of the reader was not reached.- Throws:
java.lang.NullPointerException
- if the given reader isnull
.java.io.IOException
- if there is an error reading from the reader.
-
confirm
public static boolean confirm(@Nonnull java.io.Reader reader, @Nonnull Characters characters) throws java.io.IOException
Reads a character and, if a character does not match the given set of characters, resets the reader as if the character were not read.- Parameters:
reader
- The reader the contents of which to be parsed.characters
- The characters to accept.- Returns:
true
if the given character was read, orfalse
if the next character is not one of the expected characters and was therefore replaced if the end of the reader was not reached.- Throws:
java.lang.NullPointerException
- if the given reader and/or characters isnull
.java.io.IOException
- if there is an error reading from the reader.
-
confirm
public static boolean confirm(@Nonnull java.io.Reader reader, @Nonnull java.lang.CharSequence charSequence) throws java.io.IOException
Reads a string and, if the string does not match the given character sequence, resets the reader as if the string was not read.- Parameters:
reader
- The reader the contents of which to be parsed.charSequence
- The character sequence to accept.- Returns:
true
if a string matching the character sequence was read, orfalse
if the next characters do not match the given character sequence and were therefore replaced.- Throws:
java.lang.NullPointerException
- if the given reader and/or character sequence isnull
.java.io.IOException
- if there is an error reading from the reader.
-
consumeUntil
protected static java.lang.StringBuilder consumeUntil(@Nonnull java.io.Reader reader, char untilCharacter, boolean isEndError, @Nullable java.lang.StringBuilder stringBuilder, boolean includeReached) throws java.io.IOException, ParseEOFException
Reads all characters in a reader until one of the given characters is reached. The new position will be that of the given character.- Implementation Specification:
- This implementation delegates to
consumeUntil(Reader, Characters, char, boolean, StringBuilder, boolean)
. - Parameters:
reader
- The reader the contents of which to be parsed.untilCharacter
- The character to check if the given characters isnull
.isEndError
- Whether reaching the end of the reader is an error condition.stringBuilder
- The string builder to collect the characters consumed, ornull
if the consumed characters should be discarded.includeReached
- Whether the reached character should be included, effectively making this method read past the character.- Returns:
- The string builder given, or
null
if no string builder was provided. - Throws:
java.lang.NullPointerException
- if the given reader isnull
.java.io.IOException
- if there is an error reading from the reader.ParseEOFException
- if the reader has no more characters and the end-is-error flag istrue
.
-
consumeUntil
protected static java.lang.StringBuilder consumeUntil(@Nonnull java.io.Reader reader, @Nullable Characters untilCharacters, boolean isEndError, @Nullable java.lang.StringBuilder stringBuilder, boolean includeReached) throws java.io.IOException, ParseEOFException
Reads all characters in a reader until one of the given characters is reached. The new position will be that of the given character.- Implementation Specification:
- This implementation delegates to
consumeUntil(Reader, Characters, char, boolean, StringBuilder, boolean)
. - Parameters:
reader
- The reader the contents of which to be parsed.untilCharacters
- The characters one of which to reach.isEndError
- Whether reaching the end of the reader is an error condition.stringBuilder
- The string builder to collect the characters consumed, ornull
if the consumed characters should be discarded.includeReached
- Whether the reached character should be included, effectively making this method read past the character.- Returns:
- The string builder given, or
null
if no string builder was provided. - Throws:
java.lang.NullPointerException
- if the given reader isnull
.java.io.IOException
- if there is an error reading from the reader.ParseEOFException
- if the reader has no more characters and the end-is-error flag istrue
.
-
consumeUntil
protected static java.lang.StringBuilder consumeUntil(@Nonnull java.io.Reader reader, @Nullable Characters untilCharacters, char untilCharacter, boolean isEndError, @Nullable java.lang.StringBuilder stringBuilder, boolean includeReached) throws java.io.IOException, ParseEOFException
Reads all characters in a reader until one of the given characters is reached. The new position will be that of the given character.- Parameters:
reader
- The reader the contents of which to be parsed.untilCharacters
- The characters one of which to reach, ornull
if the given character should be checked instead.untilCharacter
- The character to check if the given characters isnull
.isEndError
- Whether reaching the end of the reader is an error condition.stringBuilder
- The string builder to collect the characters consumed, ornull
if the consumed characters should be discarded.includeReached
- Whether the reached character should be included, effectively making this method read past the character.- Returns:
- The string builder given, or
null
if no string builder was provided. - Throws:
java.lang.NullPointerException
- if the given reader isnull
.java.io.IOException
- if there is an error reading from the reader.ParseEOFException
- if the reader has no more characters and the end-is-error flag istrue
.
-
pass
public static void pass(@Nonnull java.io.Reader reader, char character) throws java.io.IOException
Skips all characters in a reader until the given delimiter is passed or the end is reached. The new position will be immediately after that of the given character.- Implementation Specification:
- This implementation delegates to
consumeUntil(Reader, char, boolean, StringBuilder, boolean)
. - Parameters:
reader
- The reader the contents of which to be parsed.character
- The character to pass.- Throws:
java.lang.NullPointerException
- if the given reader isnull
.java.io.IOException
- if there is an error reading from the reader.ParseEOFException
- if the reader has no more characters.
-
pass
public static void pass(@Nonnull java.io.Reader reader, Characters characters) throws java.io.IOException
Skips all characters in a reader until one of the given characters or the end is reached. The new position will be immediately after that of the given character.- Implementation Specification:
- This implementation delegates to
consumeUntil(Reader, Characters, boolean, StringBuilder, boolean)
. - Parameters:
reader
- The reader the contents of which to be parsed.characters
- The characters one of which to reach.- Throws:
java.lang.NullPointerException
- if the given reader and/or characters isnull
.java.io.IOException
- if there is an error reading from the reader.
-
passRequired
public static void passRequired(@Nonnull java.io.Reader reader, char character) throws java.io.IOException, ParseEOFException
Skips all characters in a reader until the given delimiter is passed, throwing an exception if the end of the reader has been reached. The new position will be immediately after that of the given character.- Implementation Specification:
- This implementation delegates to
consumeUntil(Reader, char, boolean, StringBuilder, boolean)
. - Parameters:
reader
- The reader the contents of which to be parsed.character
- The character to pass.- Throws:
java.lang.NullPointerException
- if the given reader isnull
.java.io.IOException
- if there is an error reading from the reader.ParseEOFException
- if the reader has no more characters.
-
passRequired
public static void passRequired(@Nonnull java.io.Reader reader, @Nonnull Characters characters) throws java.io.IOException, ParseEOFException
Skips all characters in a reader until one of the given characters is reached, throwing an exception if the end of the reader has been reached. The new position will be immediately after that of the given character.- Implementation Specification:
- This implementation delegates to
consumeUntil(Reader, Characters, boolean, StringBuilder, boolean)
. - Parameters:
reader
- The reader the contents of which to be parsed.characters
- The characters one of which to reach.- Throws:
java.lang.NullPointerException
- if the given reader is and/or charactersnull
.java.io.IOException
- if there is an error reading from the reader.ParseEOFException
- if the reader has no more characters.
-
peek
public static int peek(@Nonnull java.io.Reader reader) throws java.io.IOException
Reads a character and, if a character was read (i.e. the reader is not out of data), resets the reader as if the character were not read.- Parameters:
reader
- The reader the contents of which to be parsed.- Returns:
- The next character that will be returned the reader's
Reader.read()
operation, or-1
if the end of the reader has been reached. - Throws:
java.lang.NullPointerException
- if the given reader isnull
.java.io.IOException
- if there is an error reading from the reader.
-
peekRequired
public static char peekRequired(@Nonnull java.io.Reader reader) throws java.io.IOException, ParseEOFException
Reads a character and and resets the reader as if the character were not read, throwing an exception if the end of the reader has been reached.- Parameters:
reader
- The reader the contents of which to be parsed.- Returns:
- The next character that will be returned the reader's
Reader.read()
operation. - Throws:
java.lang.NullPointerException
- if the given reader isnull
.java.io.IOException
- if there is an error reading from the reader.ParseEOFException
- if the reader has no more characters.
-
reach
public static void reach(@Nonnull java.io.Reader reader, char character) throws java.io.IOException
Skips all characters in a reader until the given delimiter is passed or the end is reached. The new position will be that of the given character.- Implementation Specification:
- This implementation delegates to
consumeUntil(Reader, char, boolean, StringBuilder, boolean)
. - Parameters:
reader
- The reader the contents of which to be parsed.character
- The character to pass.- Throws:
java.lang.NullPointerException
- if the given reader isnull
.java.io.IOException
- if there is an error reading from the reader.ParseEOFException
- if the reader has no more characters.
-
reach
public static void reach(@Nonnull java.io.Reader reader, @Nonnull Characters characters) throws java.io.IOException
Skips all characters in a reader until one of the given characters or the end is reached. The new position will be that of the given character.- Implementation Specification:
- This implementation delegates to
consumeUntil(Reader, Characters, boolean, StringBuilder, boolean)
. - Parameters:
reader
- The reader the contents of which to be parsed.characters
- The characters one of which to reach.- Throws:
java.lang.NullPointerException
- if the given reader and/or characters isnull
.java.io.IOException
- if there is an error reading from the reader.
-
reachRequired
public static void reachRequired(@Nonnull java.io.Reader reader, char character) throws java.io.IOException, ParseEOFException
Skips all characters in a reader until the given delimiter is passed, throwing an exception if the end of the reader has been reached. The new position will be that of the given character.- Implementation Specification:
- This implementation delegates to
consumeUntil(Reader, char, boolean, StringBuilder, boolean)
. - Parameters:
reader
- The reader the contents of which to be parsed.character
- The character to pass.- Throws:
java.lang.NullPointerException
- if the given reader isnull
.java.io.IOException
- if there is an error reading from the reader.ParseEOFException
- if the reader has no more characters.
-
reachRequired
public static void reachRequired(@Nonnull java.io.Reader reader, @Nonnull Characters characters) throws java.io.IOException, ParseEOFException
Skips all characters in a reader until one of the given characters is reached, throwing an exception if the end of the reader has been reached. The new position will be that of the given character.- Implementation Specification:
- This implementation delegates to
consumeUntil(Reader, Characters, boolean, StringBuilder, boolean)
. - Parameters:
reader
- The reader the contents of which to be parsed.characters
- The characters one of which to reach.- Throws:
java.lang.NullPointerException
- if the given reader and/or characters isnull
.java.io.IOException
- if there is an error reading from the reader.ParseEOFException
- if the reader has no more characters.
-
readEnclosedRequired
public static java.lang.String readEnclosedRequired(java.io.Reader reader, char startDelimiter, char endDelimiter) throws java.io.IOException, ParseUnexpectedDataException, ParseEOFException
Reads text from a reader that has certain required beginning and ending delimiter characters. The delimiters will be discarded.- Parameters:
reader
- The reader the contents of which to be parsed.startDelimiter
- The character to expect at the first of the characters.endDelimiter
- The character to expect at the end of the characters.- Returns:
- The characters between the delimiters.
- Throws:
java.io.IOException
- Thrown when an I/O error occurs.ParseUnexpectedDataException
- Thrown when an unexpected character is found.ParseEOFException
- Thrown when the end of the reader is reached unexpectedly.
-
readRequired
public static char readRequired(@Nonnull java.io.Reader reader) throws java.io.IOException, ParseEOFException
Reads a character, throwing an error if the end of the reader was reached.- API Note:
- This method is semantically equivalent to calling
readRequiredCount(Reader, int)
with a value of1
. - Parameters:
reader
- The reader the contents of which to be parsed.- Returns:
- The character returned from the reader's
Reader.read()
operation. - Throws:
java.lang.NullPointerException
- if the given reader isnull
.java.io.IOException
- if there is an error reading from the reader.ParseEOFException
- if the reader has no more characters.
-
readRequiredCount
public static java.lang.String readRequiredCount(@Nonnull java.io.Reader reader, int count) throws java.io.IOException, ParseEOFException
Reads a given number of characters, throwing an error if the end of the reader was reached.- Parameters:
reader
- The reader the contents of which to be parsed.count
- The number of characters to read.- Returns:
- The string representing the characters returned from the reader's
Reader.read()
operation. - Throws:
java.lang.NullPointerException
- if the given reader isnull
.java.lang.IllegalArgumentException
- if the given count is less than zero.java.io.IOException
- if there is an error reading from the reader.ParseEOFException
- if the reader has no more characters.
-
readRequiredCount
public static java.lang.String readRequiredCount(@Nonnull java.io.Reader reader, @Nonnull Characters characters, int count) throws java.io.IOException, ParseUnexpectedDataException
Reads a given number of characters, throwing an error if the end of the reader was reached or if a character in the string does not match one of the given characters.- Parameters:
reader
- The reader the contents of which to be parsed.characters
- The characters to accept.count
- The number of characters to read.- Returns:
- The string representing the characters returned from the reader's
Reader.read()
operation. - Throws:
java.lang.NullPointerException
- if the given reader and/or characters isnull
.java.lang.IllegalArgumentException
- if the given count is less than zero.java.io.IOException
- if there is an error reading from the reader.ParseUnexpectedDataException
- if one of the characters read is not included in the given characters.ParseEOFException
- if the reader has no more characters.
-
readRequiredMinimumCount
public static java.lang.String readRequiredMinimumCount(@Nonnull java.io.Reader reader, @Nonnull Characters characters, int minimumCount) throws java.io.IOException
Reads at least a minimum number of characters in a reader that appear in a set of characters. The new position will either be the first character not in the range or the end of the reader.- Parameters:
reader
- The reader the contents of which to be parsed.characters
- The characters to accept.minimumCount
- The minimum number of characters to read.- Returns:
- The characters that were read.
- Throws:
java.lang.NullPointerException
- if the given reader and/or characters isnull
.java.io.IOException
- if there is an error reading from the reader.
-
readRequiredMinimumCount
public static java.lang.StringBuilder readRequiredMinimumCount(@Nonnull java.io.Reader reader, @Nonnull Characters characters, int minimumCount, @Nonnull java.lang.StringBuilder stringBuilder) throws java.io.IOException
Reads at least a minimum number of characters in a reader that appear in a set of characters. The new position will either be the first character not in the range or the end of the reader.- Parameters:
reader
- The reader the contents of which to be parsed.characters
- The characters to accept.stringBuilder
- The string builder to which the characters will be appended.minimumCount
- The minimum number of characters to read.- Returns:
- The given string builder with the characters appended.
- Throws:
java.lang.NullPointerException
- if the given reader, characters, and/or string builder isnull
.java.io.IOException
- if there is an error reading from the reader.
-
readPast
public static java.lang.String readPast(@Nonnull java.io.Reader reader, @Nonnull Characters characters) throws java.io.IOException
Reads all characters in a reader until one of the given characters or the end is reached. The reached character will be included and the new position will be immediately after that of the given character.- Implementation Specification:
- This implementation delegates to
consumeUntil(Reader, Characters, boolean, StringBuilder, boolean)
. - Parameters:
reader
- The reader the contents of which to be parsed.characters
- The characters one of which to reach.- Returns:
- The string read until the given character or the empty string if there is no such a character.
- Throws:
java.lang.NullPointerException
- if the given reader and/or characters isnull
.java.io.IOException
- if there is an error reading from the reader.
-
readPastRequired
public static java.lang.String readPastRequired(@Nonnull java.io.Reader reader, @Nonnull Characters characters) throws java.io.IOException
Reads all characters in a reader until one of the given characters. The reached character will be included and the new position will be immediately after that of the given character.- Implementation Specification:
- This implementation delegates to
consumeUntil(Reader, Characters, boolean, StringBuilder, boolean)
. - Parameters:
reader
- The reader the contents of which to be parsed.characters
- The characters one of which to reach.- Returns:
- The string read until the given character or the empty string if there is no such a character.
- Throws:
java.lang.NullPointerException
- if the given reader and/or characters isnull
.java.io.IOException
- if there is an error reading from the reader.ParseEOFException
- if the reader has no more characters.
-
readUntil
public static java.lang.String readUntil(@Nonnull java.io.Reader reader, @Nonnull Characters characters) throws java.io.IOException
Reads all characters in a reader until one of the given characters or the end is reached. The new position will be that of the given character.- Implementation Specification:
- This implementation delegates to
consumeUntil(Reader, Characters, boolean, StringBuilder, boolean)
. - Parameters:
reader
- The reader the contents of which to be parsed.characters
- The characters one of which to reach.- Returns:
- The string read until the given character or the empty string if there is no such a character.
- Throws:
java.lang.NullPointerException
- if the given reader and/or characters isnull
.java.io.IOException
- if there is an error reading from the reader.
-
readUntilRequired
public static java.lang.String readUntilRequired(@Nonnull java.io.Reader reader, char character) throws java.io.IOException, ParseEOFException
Reads all characters in a reader until the given delimiter is reached, throwing an exception if the end of the reader has been reached. The new position will be that of the given character.- Implementation Specification:
- This implementation delegates to
consumeUntil(Reader, char, boolean, StringBuilder, boolean)
. - Parameters:
reader
- The reader the contents of which to be parsed.character
- The character to pass.- Returns:
- The string read until the given character.
- Throws:
java.lang.NullPointerException
- if the given reader isnull
.java.io.IOException
- if there is an error reading from the reader.ParseEOFException
- if the reader has no more characters.
-
readUntilRequired
public static java.lang.String readUntilRequired(@Nonnull java.io.Reader reader, @Nonnull Characters characters) throws java.io.IOException, ParseEOFException
Reads all characters in a reader until one of the given characters is reached, throwing an exception if the end of the reader has been reached. The new position will be that of the given character.- Implementation Specification:
- This implementation delegates to
consumeUntil(Reader, Characters, boolean, StringBuilder, boolean)
. - Parameters:
reader
- The reader the contents of which to be parsed.characters
- The characters one of which to reach.- Returns:
- The string read until the given character.
- Throws:
java.lang.NullPointerException
- if the given reader and/or characters isnull
.java.io.IOException
- if there is an error reading from the reader.ParseEOFException
- if the reader has no more characters.
-
readWhile
public static java.lang.String readWhile(@Nonnull java.io.Reader reader, @Nonnull Characters characters) throws java.io.IOException
Reads all characters in a reader that appear within a given set of characters. The new position will either be the first character not in the characters or the end of the reader.- Parameters:
reader
- The reader the contents of which to be parsed.characters
- The characters to read.- Returns:
- The characters that were read.
- Throws:
java.lang.NullPointerException
- if the given reader and/or characters isnull
.java.io.IOException
- if there is an error reading from the reader.
-
readWhile
public static java.lang.StringBuilder readWhile(@Nonnull java.io.Reader reader, @Nonnull Characters characters, @Nonnull java.lang.StringBuilder stringBuilder) throws java.io.IOException
Reads all characters in a reader that appear within a given set of characters and collects them in a given string builder. The new position will either be the first character not in the characters or the end of the reader.- Implementation Specification:
- This implementation delegates to
consumeWhile(Reader, Characters, StringBuilder)
. - Parameters:
reader
- The reader the contents of which to be parsed.characters
- The characters to read.stringBuilder
- The string builder to collect the read characters.- Returns:
- The given string builder with the characters that were read added.
- Throws:
java.lang.NullPointerException
- if the given reader, characters, and/or string builder isnull
.java.io.IOException
- if there is an error reading from the reader.
-
skip
public static int skip(@Nonnull java.io.Reader reader, @Nonnull Characters characters) throws java.io.IOException
Skips over characters in a reader that appear within a given set of characters. The new position will either be the first character not in the characters or the end of the reader.- Implementation Specification:
- This implementation delegates to
consumeWhile(Reader, Characters, StringBuilder)
. - Parameters:
reader
- The reader the contents of which to be parsed.characters
- The characters to skip.- Returns:
- The next character that will be returned the reader's
Reader.read()
operation, or-1
if the end of the reader has been reached. - Throws:
java.lang.NullPointerException
- if the given reader and/or characters isnull
.java.io.IOException
- if there is an error reading from the reader.
-
-