public class CharReadBuffer extends Object
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 and Description |
---|
CharReadBuffer(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.
|
Modifier and Type | Method and Description |
---|---|
int |
charAt(int index)
Get the character at the given buffer index or if the index
is past the end of the content.
|
boolean |
hasMoreCharacters()
Return true if more characters are available from the read buffer.
|
int |
makeAvailable(int n)
Attempt to make at least
n characters available in the buffer, reading
characters from the underlying reader as needed. |
int |
peek()
Return the next character in the buffer without removing it.
|
String |
peekString(int len)
Return a string from the buffer without removing it.
|
void |
push(char ch)
Push a character back onto the read buffer.
|
void |
pushString(String str)
Push a string back onto the read buffer.
|
int |
read()
Remove and return the next character in the buffer.
|
String |
readString(int len)
Remove and return a string from the buffer.
|
int |
skip(int n)
Skip
n characters from the stream. |
public CharReadBuffer(Reader reader)
reader
- underlying reader instanceNullPointerException
- if reader
is nullpublic CharReadBuffer(Reader reader, int initialCapacity)
reader
- underlying reader instanceinitialCapacity
- the initial capacity of the internal buffer; the buffer
is resized as neededNullPointerException
- if reader
is nullIllegalArgumentException
- if initialCapacity
is less than one.public CharReadBuffer(Reader reader, int initialCapacity, int minRead)
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 readerNullPointerException
- if reader
is nullIllegalArgumentException
- if initialCapacity
or minRead
are less than one.public boolean hasMoreCharacters()
UncheckedIOException
- if an I/O error occurspublic int makeAvailable(int n)
n
characters available in the buffer, reading
characters from the underlying reader as needed. The number of characters available
is returned.n
- number of characters requested to be availableUncheckedIOException
- if an I/O error occurspublic int read()
UncheckedIOException
- if an I/O error occurspeek()
public String readString(int len)
len
. Null is
returned if no more characters are available.len
- requested length of the stringIllegalArgumentException
- if len
is less than 0UncheckedIOException
- if an I/O error occurspeekString(int)
public int peek()
UncheckedIOException
- if an I/O error occursread()
public String peekString(int len)
len
. Null is
returned if no more characters are available.len
- requested length of the stringIllegalArgumentException
- if len
is less than 0UncheckedIOException
- if an I/O error occursreadString(int)
public int charAt(int index)
index
- index of the character to receive relative to the buffer start-1
if the character is
past the end of the stream contentUncheckedIOException
- if an I/O exception occurspublic int skip(int n)
n
characters from the stream. Characters are first skipped from the buffer
and then from the underlying reader using Reader.skip(long)
if needed.n
- number of character to skipIllegalArgumentException
- if n
is negativeUncheckedIOException
- if an I/O error occurspublic void push(char ch)
read()
or peek()
.ch
- character to push onto the read bufferpublic void pushString(String str)
read()
or peek()
.str
- string to push onto the read bufferCopyright © 2016–2021 The Apache Software Foundation. All rights reserved.