Class TemplateReader
java.lang.Object
java.io.Reader
fc.util.pagetemplate.TemplateReader
- All Implemented Interfaces:
Closeable, AutoCloseable, Readable
A Reader suitable for lexing. Supports all of:
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 Summary
ConstructorsConstructorDescriptionTemplateReader
(File file) Creates a reader using the UTF-8 encoding.TemplateReader
(File file, String encoding) Creates a reader with the specified non-null encoding.Creates a new TemplateReader wrapping the specified reader -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
Useful for inserting included files into the stream and then parsing that content in-line with the rest of the file.static void
boolean
boolean
match
(int target) Tries to read/consumes the specified char and returns true if successful.boolean
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
Skips all whitespace characters such that the nextread()
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 charactersMethods inherited from class Reader
mark, nullReader, of, read, read, readAllAsString, readAllLines, ready, reset, skip, transferTo
-
Constructor Details
-
TemplateReader
Creates a new TemplateReader wrapping the specified reader- Throws:
IOException
-
TemplateReader
Creates a reader with the specified non-null encoding.- Throws:
IOException
-
TemplateReader
Creates a reader using the UTF-8 encoding.- Throws:
IOException
-
-
Method Details
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classReader
- Throws:
IOException
-
read
- Overrides:
read
in classReader
- Throws:
IOException
-
read
- Specified by:
read
in classReader
- Throws:
IOException
-
unread
Unreads the current character (which could be EOF) so that the next read will return the current character (or EOF) again.- Throws:
IOException
-
unread
Unreads the specified number of characters- Throws:
IOException
-
insertIntoStream
Useful for inserting included files into the stream and then parsing that content in-line with the rest of the file.- Throws:
IOException
-
insertIntoStream
Useful for inserting included files into the stream and then parsing that content in-line with the rest of the file.- Throws:
IOException
-
peek
- Throws:
IOException
-
skipWhitespace
Skips all whitespace characters such that the nextread()
will return the next non-whitespace character (or EOF if there are no more characters).- Throws:
IOException
-
match
Tries to read/consumes the specified char and returns true if successful. If the specified char is not found, does not consume anything and returns false.- Throws:
IOException
-
match
Tries to read/consumes the specified non-null string and returns true if successful. If the specified string is not found, does not consume anything and returns false.- Throws:
IOException
-
matchIgnoreCase
- Throws:
IOException
-
markSupported
- Overrides:
markSupported
in classReader
-
getLine
-
getCol
-
main
- Throws:
IOException
-