com.martiansoftware.snip.util
Class MacroInputStream

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.FilterInputStream
          extended bycom.martiansoftware.snip.util.MacroInputStream

public class MacroInputStream
extends java.io.FilterInputStream

TODO: write docs.

Author:
Marty Lamb

Field Summary
static java.lang.String DEFAULT_MACROEND
          The default indicator of the end of a macro.
static java.lang.String DEFAULT_MACROSTART
          The default indicator of the beginning of a macro.
static int DEFAULT_MAXMACROLENGTH
          The default maximum lookahead when reading macros.
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
MacroInputStream(java.io.InputStream in, MacroProcessor processor)
          Creates a new MacroInputStream wrapping the specified InputStream and using the specified MacroProcessor.
MacroInputStream(java.io.InputStream in, MacroProcessor processor, int maxMacroLength)
          Creates a new MacroInputStream wrapping the specified InputStream and using the specified MacroProcessor and maximum macro lookahead.
 
Method Summary
 java.lang.String getMacroEnd()
          Returns the macro end delimiter.
 java.lang.String getMacroStart()
          Returns the macro start delimiter.
 int getMaxBufSize()
          Returns the maxBufSize.
 int getMaxLeftRecursionDepth()
          Returns the maxLeftRecursionDepth.
 int getMaxMacroLength()
          Returns the max macro lookahead.
 int read()
          Returns the next character from the underlying InputStream, performing macro evaluations along the way.
 int read(byte[] b)
          Reads into the specified byte array, filling it if possible.
 int read(byte[] b, int offset, int length)
          Attempts to read length bytes into the specified byte array, beginning at index offset.
 void setMacroDelimiters(java.lang.String macroStart, java.lang.String macroEnd)
          Sets the macro start and end delimiters.
 void setMacroEnd(java.lang.String macroEnd)
          Sets the macro end indicator.
 void setMacroStart(java.lang.String macroStart)
          Sets the macro start indicator.
 void setMaxBufSize(int maxBufSize)
          Sets the maxBufSize.
 void setMaxLeftRecursionDepth(int maxLeftRecursionDepth)
          Sets the maxLeftRecursionDepth.
 void setMaxMacroLength(int maxMacroLength)
          Sets the max macro lookahead to use.
 
Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MAXMACROLENGTH

public static final int DEFAULT_MAXMACROLENGTH
The default maximum lookahead when reading macros.

See Also:
Constant Field Values

DEFAULT_MACROSTART

public static final java.lang.String DEFAULT_MACROSTART
The default indicator of the beginning of a macro.

See Also:
Constant Field Values

DEFAULT_MACROEND

public static final java.lang.String DEFAULT_MACROEND
The default indicator of the end of a macro.

See Also:
Constant Field Values
Constructor Detail

MacroInputStream

public MacroInputStream(java.io.InputStream in,
                        MacroProcessor processor)
Creates a new MacroInputStream wrapping the specified InputStream and using the specified MacroProcessor.

Parameters:
in - the InputStream to wrap.
processor - the MacroProcessor to use.

MacroInputStream

public MacroInputStream(java.io.InputStream in,
                        MacroProcessor processor,
                        int maxMacroLength)
Creates a new MacroInputStream wrapping the specified InputStream and using the specified MacroProcessor and maximum macro lookahead.

Parameters:
in - the InputStream to wrap.
processor - the MacroProcessor to use.
maxMacroLength - the maximum macro lookahead to use.
Method Detail

setMaxMacroLength

public void setMaxMacroLength(int maxMacroLength)
Sets the max macro lookahead to use.

Parameters:
maxMacroLength - the max macro lookahead to use.

getMaxMacroLength

public int getMaxMacroLength()
Returns the max macro lookahead.

Returns:
the max macro lookahead.

setMacroStart

public void setMacroStart(java.lang.String macroStart)
Sets the macro start indicator.

Parameters:
macroStart - the macro start indicator.

setMacroEnd

public void setMacroEnd(java.lang.String macroEnd)
Sets the macro end indicator.

Parameters:
macroEnd - the macro end indicator.

getMacroStart

public java.lang.String getMacroStart()
Returns the macro start delimiter.

Returns:
the macro start delimiter.

getMacroEnd

public java.lang.String getMacroEnd()
Returns the macro end delimiter.

Returns:
the macro end delimiter.

setMacroDelimiters

public void setMacroDelimiters(java.lang.String macroStart,
                               java.lang.String macroEnd)
Sets the macro start and end delimiters.

Parameters:
macroStart - the macro start delimiter.
macroEnd - the macro end delimiter.

read

public int read()
         throws java.io.IOException
Returns the next character from the underlying InputStream, performing macro evaluations along the way.

Returns:
the next character from the underlying InputStream(with macros evaluated), or -1 if the end of the stream has been reached.
Throws:
java.io.IOException - if an IO error occurs.

read

public int read(byte[] b)
         throws java.io.IOException
Reads into the specified byte array, filling it if possible.

Parameters:
b - the array into which to read
Returns:
the number of bytes read, or -1 if nothing was read and the end of the stream has been reached.
Throws:
java.io.IOException - if an I/O error occurs

read

public int read(byte[] b,
                int offset,
                int length)
         throws java.io.IOException
Attempts to read length bytes into the specified byte array, beginning at index offset.

Parameters:
b - the array into which to read
offset - the beginning index at which the array should be filled
length - the maximum number of bytes to read
Returns:
the number of bytes read, or -1 if nothing was read and the end of the stream has been reached.
Throws:
java.io.IOException - if an I/O error occurs

getMaxBufSize

public int getMaxBufSize()
Returns the maxBufSize.

Returns:
int

getMaxLeftRecursionDepth

public int getMaxLeftRecursionDepth()
Returns the maxLeftRecursionDepth.

Returns:
int

setMaxBufSize

public void setMaxBufSize(int maxBufSize)
Sets the maxBufSize.

Parameters:
maxBufSize - The maxBufSize to set

setMaxLeftRecursionDepth

public void setMaxLeftRecursionDepth(int maxLeftRecursionDepth)
Sets the maxLeftRecursionDepth.

Parameters:
maxLeftRecursionDepth - The maxLeftRecursionDepth to set