utilMDE
Class EntryReader

Object
  extended by Reader
      extended by BufferedReader
          extended by LineNumberReader
              extended by EntryReader
All Implemented Interfaces:
Closeable, Iterable<String>, Readable, Iterator<String>
Direct Known Subclasses:
MultiReader

public class EntryReader
extends LineNumberReader
implements Iterable<String>, Iterator<String>

Class that reads "entries" from a file. In the simplest case, entries can be lines. It supports: include files, comments, and multi-line entries (paragraphs). The syntax of each of these is customizable.

See Also:
and @see #set_entry_start_stop(String,String)

Nested Class Summary
static class EntryReader.Entry
          Descriptor for an entry (paragraph)
 
Field Summary
 Pattern entry_start_re
          Regular expression that starts a long entry (paragraph).
 Pattern entry_stop_re
          Regular expression that terminates a long entry.
 
Fields inherited from class Reader
lock
 
Constructor Summary
EntryReader(File file)
          Create a EntryReader that does not support comments or include directives.
EntryReader(File file, String charsetName)
          Create a EntryReader that does not support comments or include directives.
EntryReader(File file, String comment_re, String include_re)
          Create a EntryReader
EntryReader(InputStream in)
          Create a EntryReader that does not support comments or include directives.
EntryReader(InputStream in, String filename)
          Create a EntryReader that uses the default character set and does not support comments or include directives.
EntryReader(InputStream in, String charsetName, String filename)
          Create a EntryReader that does not support comments or include directives.
EntryReader(InputStream in, String filename, String comment_re_string, String include_re_string)
          Create a EntryReader
EntryReader(InputStream in, String charsetName, String filename, String comment_re_string, String include_re_string)
           
EntryReader(Reader reader)
          Create a EntryReader that does not support comments or include directives.
EntryReader(Reader reader, String filename, String comment_re_string, String include_re_string)
          Create a EntryReader
EntryReader(String filename)
          Create a EntryReader that does not support comments or include directives.
EntryReader(String filename, String charsetName)
          Create a EntryReader that does not support comments or include directives.
EntryReader(String filename, String comment_re, String include_re)
          Create a new EntryReader starting with the specified file.
 
Method Summary
 EntryReader.Entry get_entry()
          Returns the next entry (paragraph) in the file.
 String get_filename()
          Deprecated.  
 long get_line_number()
          Deprecated.  
 String getFileName()
          Returns the current filename
 int getLineNumber()
          Return the current line number in the current file.
 boolean hasNext()
          Returns whether or not there is another line to read.
 Iterator<String> iterator()
          Returns a line-by-line interator for this file.
static void main(String[] args)
          Simple example
 void mark(int readAheadLimit)
          Mark the present position in the stream.
 String next()
          Returns the next line in the multi-file.
 void putback(String line)
          Puts the specified line back in the input.
 int read()
          Read a single character.
 int read(char[] cbuf, int off, int len)
          Read characters into a portion of an array.
 String readLine()
          Read a line, ignoring comments and processing includes.
 void remove()
          remove() is not supported
 void reset()
          Reset the stream to the most recent mark.
 void set_entry_start_stop(Pattern entry_start_re, Pattern entry_stop_re)
          Set the regular expressions for the start and stop of long entries (multiple lins that are read as a group by get_entry()).
 void set_entry_start_stop(String entry_start_re, String entry_stop_re)
          Set the regular expressions for the start and stop of long entries (multiple lins that are read as a group by get_entry()).
 void setLineNumber(int lineNumber)
          Set the current line number in the current file.
 long skip(long n)
          Skip characters.
 
Methods inherited from class BufferedReader
close, markSupported, ready
 
Methods inherited from class Reader
read, read
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entry_start_re

public Pattern entry_start_re
Regular expression that starts a long entry (paragraph). By default, paragraphs are separated by blank lines.


entry_stop_re

public Pattern entry_stop_re
Regular expression that terminates a long entry. Long entries can also be terminated by the start of a new long entry or the end of the current file.

Constructor Detail

EntryReader

public EntryReader(InputStream in,
                   String charsetName,
                   String filename,
                   String comment_re_string,
                   String include_re_string)
            throws UnsupportedEncodingException
Throws:
UnsupportedEncodingException

EntryReader

public EntryReader(InputStream in,
                   String charsetName,
                   String filename)
            throws UnsupportedEncodingException
Create a EntryReader that does not support comments or include directives.

Throws:
UnsupportedEncodingException
See Also:
EntryReader(InputStream,String,String,String)

EntryReader

public EntryReader(InputStream in,
                   String filename,
                   String comment_re_string,
                   String include_re_string)
Create a EntryReader

Parameters:
in - Initial source
filename - Non-null file name for stream being read
comment_re_string - Regular expression that matches comments. Any text that matches comment_re is removed. A line that is entirely a comment is ignored
include_re_string - Regular expression that matches include directives. The expression should define one group that contains the include file name

EntryReader

public EntryReader(InputStream in,
                   String filename)
Create a EntryReader that uses the default character set and does not support comments or include directives.

See Also:
EntryReader(InputStream,String,String,String,String)

EntryReader

public EntryReader(InputStream in)
Create a EntryReader that does not support comments or include directives.

See Also:
EntryReader(InputStream,String,String,String)

EntryReader

public EntryReader(Reader reader,
                   String filename,
                   String comment_re_string,
                   String include_re_string)
Create a EntryReader

Parameters:
reader - Initial source
comment_re_string - Regular expression that matches comments. Any text that matches comment_re is removed. A line that is entirely a comment is ignored
include_re_string - Regular expression that matches include directives. The expression should define one group that contains the include file name

EntryReader

public EntryReader(Reader reader)
Create a EntryReader that does not support comments or include directives.

See Also:
EntryReader(Reader,String,String,String)

EntryReader

public EntryReader(File file,
                   String comment_re,
                   String include_re)
            throws IOException
Create a EntryReader

Parameters:
file - Initial file to read.
comment_re - Regular expression that matches comments. Any text that matches comment_re is removed. A line that is entirely a comment is ignored.
include_re - Regular expression that matches include directives. The expression should define one group that contains the include file name.
Throws:
IOException

EntryReader

public EntryReader(File file)
            throws IOException
Create a EntryReader that does not support comments or include directives.

Throws:
IOException
See Also:
EntryReader(File,String,String)

EntryReader

public EntryReader(File file,
                   String charsetName)
            throws IOException
Create a EntryReader that does not support comments or include directives.

Throws:
IOException
See Also:
EntryReader(File,String,String)

EntryReader

public EntryReader(String filename,
                   String comment_re,
                   String include_re)
            throws IOException
Create a new EntryReader starting with the specified file.

Throws:
IOException
See Also:
EntryReader(File,String,String)

EntryReader

public EntryReader(String filename)
            throws IOException
Create a EntryReader that does not support comments or include directives.

Throws:
IOException
See Also:
EntryReader(String,String,String)

EntryReader

public EntryReader(String filename,
                   String charsetName)
            throws IOException
Create a EntryReader that does not support comments or include directives.

Throws:
IOException
See Also:
EntryReader(String,String,String)
Method Detail

readLine

public String readLine()
                throws IOException
Read a line, ignoring comments and processing includes. Note that a line that is completely a comment is completely ignored (and not returned as a blank line). Returns null at end of file.

Overrides:
readLine in class LineNumberReader
Throws:
IOException

iterator

public Iterator<String> iterator()
Returns a line-by-line interator for this file.

Warning: This does not return a fresh iterator each time. The iterator is a singleton, the same one is returned each time, and a new one can never be created after it is exhausted.

Specified by:
iterator in interface Iterable<String>

hasNext

public boolean hasNext()
Returns whether or not there is another line to read. Any IOExceptions are turned into errors (because the definition of hasNext() in Iterator doesn't throw any exceptions).

Specified by:
hasNext in interface Iterator<String>

next

public String next()
Returns the next line in the multi-file. Throws NoSuchElementException at end of file.

Specified by:
next in interface Iterator<String>

remove

public void remove()
remove() is not supported

Specified by:
remove in interface Iterator<String>

get_entry

public EntryReader.Entry get_entry()
                            throws IOException
Returns the next entry (paragraph) in the file. Entries are separated by blank lines unless the entry started with entry_start_re (see set_entry_start_stop(java.lang.String, java.lang.String)). If no more entries are available, returns null.

Throws:
IOException

get_filename

@Deprecated
public String get_filename()
Deprecated. 

See Also:
getFileName()

getFileName

public String getFileName()
Returns the current filename


get_line_number

@Deprecated
public long get_line_number()
Deprecated. 

See Also:
getLineNumber()

getLineNumber

public int getLineNumber()
Return the current line number in the current file.

Overrides:
getLineNumber in class LineNumberReader

setLineNumber

public void setLineNumber(int lineNumber)
Set the current line number in the current file.

Overrides:
setLineNumber in class LineNumberReader

set_entry_start_stop

public void set_entry_start_stop(String entry_start_re,
                                 String entry_stop_re)
Set the regular expressions for the start and stop of long entries (multiple lins that are read as a group by get_entry()).


set_entry_start_stop

public void set_entry_start_stop(Pattern entry_start_re,
                                 Pattern entry_stop_re)
Set the regular expressions for the start and stop of long entries (multiple lins that are read as a group by get_entry()).


putback

public void putback(String line)
Puts the specified line back in the input. Only one line can be put back.


mark

public void mark(int readAheadLimit)
Mark the present position in the stream.

Overrides:
mark in class LineNumberReader

read

public int read()
Read a single character.

Overrides:
read in class LineNumberReader

read

public int read(char[] cbuf,
                int off,
                int len)
Read characters into a portion of an array.

Overrides:
read in class LineNumberReader

reset

public void reset()
Reset the stream to the most recent mark.

Overrides:
reset in class LineNumberReader

skip

public long skip(long n)
Skip characters.

Overrides:
skip in class LineNumberReader

main

public static void main(String[] args)
                 throws IOException
Simple example

Throws:
IOException