public final class TemplateReader extends Reader
peek
,
read
and unread
. (no JDK 1.5 reader class has
all of those). Mark/reset is not supported because it's too complex to
implement given the current fixed-buffer implementation of this
class. (on the flip-side this implementation does allow to read
very large files without risk of running out of JDK memory).
Note 1: If this class is invoked from the command line, setting the dbg
flag in the code to true
is useful.
Constructor and Description |
---|
TemplateReader(File file)
Creates a reader using the UTF-8 encoding.
|
TemplateReader(File file,
String encoding)
Creates a reader with the specified non-null encoding.
|
TemplateReader(Reader r)
Creates a new TemplateReader wrapping the specified reader
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
int |
getCol() |
int |
getLine() |
void |
insertIntoStream(File file)
Useful for inserting included files into the stream and then parsing that content in-line
with the rest of the file.
|
void |
insertIntoStream(Reader r)
Useful for inserting included files into the stream and then parsing that content in-line
with the rest of the file.
|
static void |
main(String[] args) |
boolean |
markSupported() |
boolean |
match(int target)
Tries to read/consumes the specified char and returns true
if successful.
|
boolean |
match(String target)
Tries to read/consumes the specified non-null string and returns true
if successful.
|
boolean |
matchIgnoreCase(String target) |
int |
peek() |
int |
read() |
int |
read(char[] buf,
int start,
int len) |
void |
skipWhitespace()
Skips all whitespace characters such that the next
read will
return the next non-whitespace character (or EOF if there are no
more characters). |
void |
unread()
Unreads the current character (which could be EOF) so that the next read will
return the current character (or EOF) again.
|
void |
unread(int count)
Unreads the specified number of characters
|
public TemplateReader(Reader r) throws IOException
IOException
public TemplateReader(File file, String encoding) throws IOException
IOException
public TemplateReader(File file) throws IOException
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class Reader
IOException
public int read() throws IOException
read
in class Reader
IOException
public int read(char[] buf, int start, int len) throws IOException
read
in class Reader
IOException
public void unread() throws IOException
IOException
public void unread(int count) throws IOException
IOException
public void insertIntoStream(File file) throws IOException
IOException
public void insertIntoStream(Reader r) throws IOException
IOException
public int peek() throws IOException
IOException
public void skipWhitespace() throws IOException
read
will
return the next non-whitespace character (or EOF if there are no
more characters).IOException
public boolean match(int target) throws IOException
IOException
public boolean match(String target) throws IOException
IOException
public boolean matchIgnoreCase(String target) throws IOException
IOException
public boolean markSupported()
markSupported
in class Reader
public int getLine()
public int getCol()
public static void main(String[] args) throws IOException
IOException