Class BracketFilteredReader

java.lang.Object
  |
  +--java.io.Reader
        |
        +--java.io.BufferedReader
              |
              +--BracketFilteredReader

public class BracketFilteredReader
extends BufferedReader

This extension of BufferedReader reads a given Reader linewisely and substitutes any bracket by a dot, if it occurs within a Java comment, a Java String literal, or a Java char literal, see Java Language Specification - Lexical Structure.
It is only allowed to call readLine() for reading the given Reader, and this is the only method with behaviour different to BufferedReader.

Author:
Christian Liebchen
See Also:
readLine(), brackets, replaceChar

Field Summary
static char[] brackets
          The (bracket) characters to be substituted by replaceChar, if they do occur within a char or string literal, or within a comment.
static char replaceChar
          The character to substitute (bracket) characters brackets, if they do occur within a char or string literal, or within a comment.
 
Constructor Summary
BracketFilteredReader(Reader r)
          Initializes this BracketFilteredReader.
 
Method Summary
static void main(String[] args)
          Filters args[0] to targetfile args[0]+".out".
 int read()
          Please use readLine() instead.
 int read(char[] cbuf, int off, int len)
          Please use readLine() instead.
 String readLine()
          Reads the next line from this reader and replaces any bracket character within comments or literals by a dot.
 
Methods inherited from class java.io.BufferedReader
close, mark, markSupported, ready, reset, skip
 
Methods inherited from class java.io.Reader
read
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

brackets

public static final char[] brackets
The (bracket) characters to be substituted by replaceChar, if they do occur within a char or string literal, or within a comment.

See Also:
replaceChar

replaceChar

public static final char replaceChar
The character to substitute (bracket) characters brackets, if they do occur within a char or string literal, or within a comment.

See Also:
brackets, Constant Field Values
Constructor Detail

BracketFilteredReader

public BracketFilteredReader(Reader r)
Initializes this BracketFilteredReader.

See Also:
BufferedReader.BufferedReader(Reader)
Method Detail

read

public int read()
         throws UnsupportedOperationException
Please use readLine() instead.

Overrides:
read in class BufferedReader
Throws:
UnsupportedOperationException - everytime

read

public int read(char[] cbuf,
                int off,
                int len)
         throws UnsupportedOperationException
Please use readLine() instead.

Overrides:
read in class BufferedReader
Throws:
UnsupportedOperationException - everytime

readLine

public String readLine()
                throws IOException,
                       IllegalStateException
Reads the next line from this reader and replaces any bracket character within comments or literals by a dot.

Overrides:
readLine in class BufferedReader
Returns:
the next line from this reader with bracket characters replaced a dot, if they appear within comments or literals
Throws:
IOException - if super.readLine() throws one
IllegalStateException - if syntax errors occur, such as
  • empty character literal
  • string or character literals still open at end-of-line
  • end-of-file reached before comment has been closed.
Notice that because of the many legal cases for character literals (see Java Language Specification), IllegalStateException is not thrown, if a character literal is not properly built.

main

public static void main(String[] args)
Filters args[0] to targetfile args[0]+".out".

Parameters:
args - component zero yields the input for this run of the filter