com.stevesoft.pat
Class RegexWriter

java.lang.Object
  |
  +--java.io.Writer
        |
        +--com.stevesoft.pat.RegexWriter

public class RegexWriter
extends java.io.Writer

A basic extension of FilterWriter that uses Transformer to make replacements in data as it is written out. It attempts to transform a string whenever the End-of-Line (EOL) character is written (which is, by default, the carriage return '\n'). Only the transformed portion of the line is written out, allowing the RegexWriter to wait until a complete pattern is present before attempting to write out info. Until a pattern completes, data is stored in a StringBuffer -- which can be accessed through the length() and charAt() methods of this class.

Note a subtlety here -- while a Transformer normally matches at higher priority against the pattern added to it first, this will not necessarily be true when a multi-line match is in progress because one of the complete multi-line patterns may not be completely loaded in RegexWriter's buffer. For this reason, the Transformer class is equipped with a way to add a pattern and replacement rule in three pieces -- a beginning (once this matches, nothing else in the Transformer can match until the whole pattern matches), an ending (the whole pattern is a String formed by adding the beginning and ending), and a ReplaceRule.

An illustration of this is given in the this example.


Fields inherited from class java.io.Writer
lock

 
Constructor Summary
RegexWriter(Regex r, java.io.Writer w)
           
RegexWriter(Transformer t, java.io.Writer w)
           
 
Method Summary
 char charAt(int i)
          The character at location i in the StringBuffer.
 void close()
           
 void flush()
           
 int getBufferSize()
          Get the buffer size.
 char getEOLchar()
          Deprecated.  
 int getInterval()
          Get the interval at which regex matches are checked.
 int getMaxLines()
          Deprecated.  
 int length()
          The current size of the StringBuffer in use by RegexWriter.
static void main(java.lang.String[] args)
           
 void setBufferSize(int i)
          Set the buffer size.
 void setEOLchar(char c)
          Deprecated.  
 void setInterval(int i)
          Set the interval at which regex patterns are checked.
 void setMaxLines(int ml)
          Deprecated.  
 void write(char[] ca, int b, int n)
           
 
Methods inherited from class java.io.Writer
write, write, write, write

 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RegexWriter

public RegexWriter(Transformer t,
                   java.io.Writer w)

RegexWriter

public RegexWriter(Regex r,
                   java.io.Writer w)
Method Detail

getEOLchar

public char getEOLchar()
Deprecated.  

This method no longer serves any purpose.

setEOLchar

public void setEOLchar(char c)
Deprecated.  

This method no longer serves any purpose.

getMaxLines

public int getMaxLines()
Deprecated.  

This method no longer serves any purpose.

setMaxLines

public void setMaxLines(int ml)
Deprecated.  

This method no longer serves any purpose.

write

public void write(char[] ca,
                  int b,
                  int n)
           throws java.io.IOException
Overrides:
write in class java.io.Writer

flush

public void flush()
           throws java.io.IOException
Overrides:
flush in class java.io.Writer

close

public void close()
           throws java.io.IOException
Overrides:
close in class java.io.Writer

length

public int length()
The current size of the StringBuffer in use by RegexWriter.

charAt

public char charAt(int i)
The character at location i in the StringBuffer.

setInterval

public void setInterval(int i)
Set the interval at which regex patterns are checked.

getInterval

public int getInterval()
Get the interval at which regex matches are checked.

getBufferSize

public int getBufferSize()
Get the buffer size.

setBufferSize

public void setBufferSize(int i)
Set the buffer size.

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception