Class CharReadBuffer
java.lang.Object
org.apache.commons.geometry.io.core.internal.CharReadBuffer
Class used to buffer characters read from an underlying
Reader.
Characters can be consumed from the buffer, examined without being consumed,
and pushed back onto the buffer. The internal bufer is resized as needed.-
Constructor Summary
ConstructorsConstructorDescriptionCharReadBuffer(Reader reader) Construct a new instance that buffers characters from the given reader.CharReadBuffer(Reader reader, int initialCapacity) Construct a new instance that buffers characters from the given reader.CharReadBuffer(Reader reader, int initialCapacity, int minRead) Construct a new instance that buffers characters from the given reader. -
Method Summary
Modifier and TypeMethodDescriptionintcharAt(int index) Get the character at the given buffer index or -1 if the index is past the end of the content.booleanReturn true if more characters are available from the read buffer.intmakeAvailable(int n) Attempt to make at leastncharacters available in the buffer, reading characters from the underlying reader as needed.intpeek()Return the next character in the buffer without removing it.peekString(int len) Return a string from the buffer without removing it.voidpush(char ch) Push a character back onto the read buffer.voidpushString(String str) Push a string back onto the read buffer.intread()Remove and return the next character in the buffer.readString(int len) Remove and return a string from the buffer.intskip(int n) Skipncharacters from the stream.
-
Constructor Details
-
CharReadBuffer
Construct a new instance that buffers characters from the given reader.- Parameters:
reader- underlying reader instance- Throws:
NullPointerException- ifreaderis null
-
CharReadBuffer
Construct a new instance that buffers characters from the given reader.- Parameters:
reader- underlying reader instanceinitialCapacity- the initial capacity of the internal buffer; the buffer is resized as needed- Throws:
NullPointerException- ifreaderis nullIllegalArgumentException- ifinitialCapacityis less than one.
-
CharReadBuffer
Construct a new instance that buffers characters from the given reader.- Parameters:
reader- underlying reader instanceinitialCapacity- the initial capacity of the internal buffer; the buffer is resized as neededminRead- the minimum number of characters to request from the reader when fetching more characters into the buffer; this can be used to limit the number of calls made to the reader- Throws:
NullPointerException- ifreaderis nullIllegalArgumentException- ifinitialCapacityorminReadare less than one.
-
-
Method Details
-
hasMoreCharacters
Return true if more characters are available from the read buffer.- Returns:
- true if more characters are available from the read buffer
- Throws:
UncheckedIOException- if an I/O error occurs
-
makeAvailable
Attempt to make at leastncharacters available in the buffer, reading characters from the underlying reader as needed. The number of characters available is returned.- Parameters:
n- number of characters requested to be available- Returns:
- number of characters available for immediate use in the buffer
- Throws:
UncheckedIOException- if an I/O error occurs
-
read
Remove and return the next character in the buffer.- Returns:
- the next character in the buffer or -1 if the end of the content has been reached
- Throws:
UncheckedIOException- if an I/O error occurs- See Also:
-
readString
Remove and return a string from the buffer. The length of the string will be the number of characters available in the buffer up tolen. Null is returned if no more characters are available.- Parameters:
len- requested length of the string- Returns:
- a string from the read buffer or null if no more characters are available
- Throws:
IllegalArgumentException- iflenis less than 0UncheckedIOException- if an I/O error occurs- See Also:
-
peek
Return the next character in the buffer without removing it.- Returns:
- the next character in the buffer or -1 if the end of the content has been reached
- Throws:
UncheckedIOException- if an I/O error occurs- See Also:
-
peekString
Return a string from the buffer without removing it. The length of the string will be the number of characters available in the buffer up tolen. Null is returned if no more characters are available.- Parameters:
len- requested length of the string- Returns:
- a string from the read buffer or null if no more characters are available
- Throws:
IllegalArgumentException- iflenis less than 0UncheckedIOException- if an I/O error occurs- See Also:
-
charAt
Get the character at the given buffer index or -1 if the index is past the end of the content. The character is not removed from the buffer.- Parameters:
index- index of the character to receive relative to the buffer start- Returns:
- the character at the given index of
-1if the character is past the end of the stream content - Throws:
UncheckedIOException- if an I/O exception occurs
-
skip
Skipncharacters from the stream. Characters are first skipped from the buffer and then from the underlying reader usingReader.skip(long)if needed.- Parameters:
n- number of character to skip- Returns:
- the number of characters skipped
- Throws:
IllegalArgumentException- ifnis negativeUncheckedIOException- if an I/O error occurs
-
push
-
pushString
-