fc.util.pagetemplate
Class TemplateReader

java.lang.Object
  extended by java.io.Reader
      extended by fc.util.pagetemplate.TemplateReader
All Implemented Interfaces:
Closeable, Readable

public final class TemplateReader
extends Reader

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
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
 
Method Summary
 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
 
Methods inherited from class java.io.Reader
mark, read, read, ready, reset, skip
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TemplateReader

public TemplateReader(Reader r)
               throws IOException
Creates a new TemplateReader wrapping the specified reader

Throws:
IOException

TemplateReader

public TemplateReader(File file,
                      String encoding)
               throws IOException
Creates a reader with the specified non-null encoding.

Throws:
IOException

TemplateReader

public TemplateReader(File file)
               throws IOException
Creates a reader using the UTF-8 encoding.

Throws:
IOException
Method Detail

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Specified by:
close in class Reader
Throws:
IOException

read

public int read()
         throws IOException
Overrides:
read in class Reader
Throws:
IOException

read

public int read(char[] buf,
                int start,
                int len)
         throws IOException
Specified by:
read in class Reader
Throws:
IOException

unread

public void unread()
            throws IOException
Unreads the current character (which could be EOF) so that the next read will return the current character (or EOF) again.

Throws:
IOException

unread

public void unread(int count)
            throws IOException
Unreads the specified number of characters

Throws:
IOException

insertIntoStream

public void insertIntoStream(File file)
                      throws IOException
Useful for inserting included files into the stream and then parsing that content in-line with the rest of the file.

Throws:
IOException

insertIntoStream

public void insertIntoStream(Reader r)
                      throws IOException
Useful for inserting included files into the stream and then parsing that content in-line with the rest of the file.

Throws:
IOException

peek

public int peek()
         throws IOException
Throws:
IOException

skipWhitespace

public void skipWhitespace()
                    throws IOException
Skips all whitespace characters such that the next read will return the next non-whitespace character (or EOF if there are no more characters).

Throws:
IOException

match

public boolean match(int target)
              throws IOException
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

public boolean match(String target)
              throws IOException
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

public boolean matchIgnoreCase(String target)
                        throws IOException
Throws:
IOException

markSupported

public boolean markSupported()
Overrides:
markSupported in class Reader

getLine

public int getLine()

getCol

public int getCol()

main

public static void main(String[] args)
                 throws IOException
Throws:
IOException