public class IncludeReader
extends java.io.Reader
By default, included readers are read seamlessly. That is, when starting or ending an inclusion, the next character is that which starts the included reader or the next one in the enclosing reader. Inclusion seams may or not be made visible with setSeamless(boolean). Called with false on an IncludeReader object, it will make its read() return IO.SOI ('start of input') or IO.EOI ('end of input'), both int constants, when starting or ending, respectively, reading an inclusion. Calling it with true re/sets seamless reading.
NB: It is possible to prevent circular inclusions, although not in all situations. Indeed there is no way, in general, for an arbitary Reader to be identified as reading from a source being actively included. However, this can be done for IncludeReaders constructed from file readers by using the IncludeReader(String) constructor and the include(String) method, which provide identifiable file names. For file readers included using this constructor and method, any circular inclusion will be detected and cause a CircularInclusionException to be thrown.
CircularInclusionException| Constructor and Description |
|---|
IncludeReader(java.io.Reader reader)
Constructs an IncludeReader with the specified Reader.
|
IncludeReader(java.lang.String file)
Constructs an IncludeReader with the specified file name.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes all readers associated with this IncludeReader.
|
int |
depth()
Returns the depth of inclusion of the current reader.
|
int |
getColumnNumber()
Returns the current column number of the current reader.
|
java.lang.String |
getFile()
Returns the name of the file associated to the current reader -
or null if the current reader is not reading from a file.
|
int |
getLineNumber()
Returns the current line number of the current reader.
|
void |
include(java.io.Reader reader)
Suspends reading from the current reader and makes further reads
proceed with the specified reader.
|
void |
include(java.lang.String file)
Suspends reading from the current reader and makes further reads
proceed with a reader from the specified file.
|
boolean |
isOutermost()
Returns true iff this is reading from the outermost reader.
|
boolean |
isSeamless()
Returns true iff this IncludeReader is seamless.
|
int |
latestChar()
Returns latest character read in the current reader.
|
void |
mark(int readAheadLimit)
This method is a simple delegation to the current underlying Reader.
|
boolean |
markSupported()
This method is a simple delegation to the current underlying Reader.
|
int |
read()
Reads and returns the next character in this IncludeReader.
|
int |
read(char[] cbuf)
Read characters into an array.
|
int |
read(char[] cbuf,
int off,
int len)
Read characters into a portion of an array.
|
boolean |
ready()
This method is a simple delegation to the current underlying Reader.
|
void |
reset()
This method is a simple delegation to the current underlying Reader.
|
void |
setFile(java.lang.String file)
Sets the name of the file associated to the current reader.
|
void |
setSeamless(boolean flag)
Sets or unsets seamless inclusion mode.
|
long |
skip(long n)
Skip n characters or until IO.EOF is found.
|
java.lang.String |
toString()
Returns a string form describing the current state of the reader.
|
public IncludeReader(java.io.Reader reader)
public IncludeReader(java.lang.String file)
throws java.io.FileNotFoundException
java.io.FileNotFoundException - (f the specified file does not exist)public final void setSeamless(boolean flag)
public final boolean isSeamless()
public final java.lang.String getFile()
public final void setFile(java.lang.String file)
public final int latestChar()
public final int getLineNumber()
public final int getColumnNumber()
public final void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.Readerjava.io.IOException - (if an I/O error occurs)public final int depth()
public final boolean isOutermost()
public final int read()
throws java.io.IOException
read in class java.io.Readerjava.io.IOException - (if an I/O error occurs)public final void include(java.io.Reader reader)
public final void include(java.lang.String file)
throws java.io.FileNotFoundException,
CircularInclusionException
java.io.FileNotFoundException - (if the specified file does not exist)CircularInclusionException - (if trying to open an enclosing Reader)public int read(char[] cbuf,
int off,
int len)
throws java.io.IOException
read in class java.io.Readercbuf - Destination bufferoff - Offset at which to start storing characterslen - Maximum number of characters to readjava.io.IOException - (if an I/O error occurs)public int read(char[] cbuf)
throws java.io.IOException
read in class java.io.Readercbuf - Destination bufferjava.io.IOException - (if an I/O error occurs)public final long skip(long n)
throws java.io.IOException
skip in class java.io.Readern - The number of characters to skipjava.lang.IllegalArgumentException - (if n is negative)java.io.IOException - (if an I/O error occurs)public boolean ready()
throws java.io.IOException
ready in class java.io.Readerjava.io.IOExceptionpublic boolean markSupported()
markSupported in class java.io.Readerpublic void mark(int readAheadLimit)
throws java.io.IOException
mark in class java.io.Readerjava.io.IOExceptionpublic void reset()
throws java.io.IOException
reset in class java.io.Readerjava.io.IOExceptionpublic final java.lang.String toString()
toString in class java.lang.Object