src2xml
Class Source

java.lang.Object
  extended by src2xml.Source

public class Source
extends java.lang.Object

A class that implements a BufferedReader wrapping a FileReader. The Reader standard interface is too restricting, specially the mark() reset() part, very dangerous if calls are inadvertently nested. This class uses a stack to support nested marks.

Limitations:

See Also:
Reader

Field Summary
static int CHUNK_SIZE
          Chunk size when buffering file [chars]
static char INVALID_CHAR
           
 
Constructor Summary
Source(java.lang.String path)
          Class constructor
 
Method Summary
 java.lang.CharSequence asCharSequence()
           
 char currChar()
          Get the current char.
 int currCharIdx()
          Get the current char index in source.
 boolean Ended()
          Check source end
protected  void finalize()
          Class destructor Ensure release of used resources
 boolean nextChar()
          Point the next char in source.
 char peekChar()
          Peek the next char in source.
 java.lang.String read(int len)
          Read a fixed length String from source
 void releaseMark()
          Discard the previous mark.
 void restoreMark()
          Restore a previously marked source position.
 void setMark()
          Mark source position.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CHUNK_SIZE

public static final int CHUNK_SIZE
Chunk size when buffering file [chars]

See Also:
Constant Field Values

INVALID_CHAR

public static final char INVALID_CHAR
See Also:
Constant Field Values
Constructor Detail

Source

public Source(java.lang.String path)
       throws java.lang.Throwable
Class constructor

Parameters:
path - The input file path
Throws:
java.lang.Throwable - If something's wrong during file buffering
See Also:
StringBuilder
Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable
Class destructor Ensure release of used resources

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

asCharSequence

public java.lang.CharSequence asCharSequence()

nextChar

public boolean nextChar()
Point the next char in source.

Returns:
returns false if no more

currChar

public char currChar()
Get the current char.

Returns:
returns the current pointed char

currCharIdx

public int currCharIdx()
Get the current char index in source.

Returns:
returns the current char index

peekChar

public char peekChar()
Peek the next char in source.

Returns:
returns the peeked char, INVALID_CHAR if source ended

read

public java.lang.String read(int len)
Read a fixed length String from source

Parameters:
len - String length to read
Returns:
The read String
See Also:
String

Ended

public boolean Ended()
Check source end

Returns:
Returns true if source ended

setMark

public void setMark()
Mark source position. Pushes the current character index in a stack.


restoreMark

public void restoreMark()
Restore a previously marked source position. Pops the last mark from stack overwriting current character index.


releaseMark

public void releaseMark()
Discard the previous mark. Pops the last mark from stack.