|
foundry-0.9.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.io.Reader | +--java.io.BufferedReader | +--foundry.io.CommentStrippingBufferedReader
A BufferedReader
that only returns characters that are not
part of a comment. A comment, for this class' purposes, starts
with a designated String
and ends with the value of the
line.separator
system property.
BufferedReader
Field Summary | |
private String |
commentLeader
The String that constitutes the comment characters. |
private int[] |
miniBuffer
A buffer used to store partial matches of multi-character comment leaders. |
private int |
miniBufferIndex
The index into the miniBuffer . |
Fields inherited from class java.io.BufferedReader |
cb, defaultCharBufferSize, defaultExpectedLineLength, in, INVALIDATED, markedChar, markedSkipLF, nChars, nextChar, readAheadLimit, skipLF, UNMARKED |
Fields inherited from class java.io.Reader |
lock, maxSkipBufferSize, skipBuffer |
Constructor Summary | |
CommentStrippingBufferedReader(Reader in)
Creates a new CommentStrippingBufferedReader that
wraps, buffers and strips comments from the supplied Reader . |
|
CommentStrippingBufferedReader(Reader in,
int size)
Creates a new CommentStrippingBufferedReader that
wraps, buffers and strips comments from the supplied Reader . |
|
CommentStrippingBufferedReader(Reader in,
int size,
String leader)
Creates a new CommentStrippingBufferedReader that
wraps, buffers and strips comments from the supplied Reader . |
|
CommentStrippingBufferedReader(Reader in,
String leader)
Creates a new CommentStrippingBufferedReader that
wraps, buffers and strips comments from the supplied Reader . |
Method Summary | |
private void |
discardLine()
Rather inefficiently throws out the remainder of a line from the current position, placing the line terminator characters into the miniBuffer . |
private void |
emptyMiniBuffer()
Empties the miniBuffer and resets the miniBufferIndex . |
String |
getCommentLeader()
Returns the current comment leader. |
int |
read()
Reads a character from the underlying Reader , buffering
as necessary and skipping:
getCommentLeader() )
any characters following comment characters up until (but not
including) the next occurrence of the value of the
line.separator system property
For example, from a line like the following:
|
int |
read(char[] cbuf,
int offset,
int len)
Adheres to the general contract for BufferedReader.read(char[], int, int) , but skips characters that
are not comments. |
String |
readLine()
Reads an entire line of text, stripping comment characters and, like its parent , disposing of
the line terminator. |
void |
setCommentLeader(String leader)
Sets the comment leader. |
Methods inherited from class java.io.BufferedReader |
|
Methods inherited from class java.io.Reader |
read |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait |
Field Detail |
private String commentLeader
String
that constitutes the comment characters.
Often set to "#
" or "//
".private int[] miniBuffer
private int miniBufferIndex
miniBuffer
.Constructor Detail |
public CommentStrippingBufferedReader(Reader in)
CommentStrippingBufferedReader
that
wraps, buffers and strips comments from the supplied Reader
.in
- the underlying Reader
public CommentStrippingBufferedReader(Reader in, String leader)
CommentStrippingBufferedReader
that
wraps, buffers and strips comments from the supplied Reader
.in
- the underlying Reader
leader
- the String
that indicates that everything
up to the next line separator but not including it is a comment; if
null
then the comment leader will be "#
"public CommentStrippingBufferedReader(Reader in, int size)
CommentStrippingBufferedReader
that
wraps, buffers and strips comments from the supplied Reader
.in
- the underlying Reader
size
- the size of the bufferBufferedReader
public CommentStrippingBufferedReader(Reader in, int size, String leader)
CommentStrippingBufferedReader
that
wraps, buffers and strips comments from the supplied Reader
.in
- the underlying Reader
size
- the size of the bufferleader
- the String
that indicates that everything
up to the next line separator but not including it is a comment;
if null
, then the comment leader will be
"#
"Method Detail |
public void setCommentLeader(String leader) throws NullPointerException
CommentStrippingBufferedReader
to ignore some data
from the stream.leader
- the String
that indicates that everything
up to the next line separator but not including it is a commentNullPointerException
- if leader
is
null
public String getCommentLeader()
null
.public int read() throws IOException
Reader
, buffering
as necessary and skipping:
getCommentLeader()
)
line.separator
system property
...successive calls to this method will yield "name=ljnelson # the name of the user type=author
n
",
"a
", "m
", "e
",
"=
", "l
", "j
",
"n
", "e
", "l
",
"s
", "o
", "n
",
"
", "\n
", "t
",
"y
", "p
", "e
",
"=
", "a
", "u
",
"t
", "h
", "o
",
"r
", and "\n
" (assuming the value of
the line.separator
system property is
"\n
" and not "\r\n
").read
in class BufferedReader
-1
if
the end of the underlying stream has been reachedIOException
- if some input/output exception occurspublic int read(char[] cbuf, int offset, int len) throws IOException
BufferedReader.read(char[], int, int)
, but skips characters that
are not comments. See read()
for a detailed explanation
of how characters are considered to be comments.read
in class BufferedReader
cbuf
- the char
array to place read characters intooffset
- the index within cbuf
at which to
begin inserting characterslen
- the number of characters to insertIOException
- if an input/output exception occursprivate final void discardLine() throws IOException
miniBuffer
.IOException
- if an input/output error occursprivate final void emptyMiniBuffer()
miniBuffer
and resets the miniBufferIndex
.public String readLine() throws IOException
parent
, disposing of
the line terminator.readLine
in class BufferedReader
null
if there are no more
lines to be readIOException
- if an input/output exception occurs
|
foundry-0.9.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |