org.cdlib.xtf.util
Class DocTypeDeclRemover
Object
InputStream
FilterInputStream
BufferedInputStream
DocTypeDeclRemover
- All Implemented Interfaces:
- Closeable
public class DocTypeDeclRemover
- extends BufferedInputStream
The parser that comes with the JDK always tries to resolve DOCTYPE
declarations in an XML file, but will barf if it can't. We want to be
able to work with such documents regardless of whether the DOCTYPE
is resolvable or not. Hence this class, which filters out DOCTYPE
declarations entirely.
Field Summary |
private static int |
BLOCK_SIZE
How many bytes to scan before giving up |
private boolean |
firstTime
Marks whether we've scanned the initial block for a DOCTYPE decl |
Fields inherited from class BufferedInputStream |
buf, count, marklimit, markpos, pos |
Fields inherited from class FilterInputStream |
in |
Constructor Summary |
DocTypeDeclRemover(InputStream in)
Default constructor: records the input stream to filter. |
Method Summary |
private int |
findEnd(String s,
int start)
|
int |
read()
See
the general contract of the read
method of InputStream . |
int |
read(byte[] b,
int off,
int len)
Read a block of bytes. |
Methods inherited from class BufferedInputStream |
available, close, mark, markSupported, reset, skip |
Methods inherited from class FilterInputStream |
read |
Methods inherited from class Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
firstTime
private boolean firstTime
- Marks whether we've scanned the initial block for a DOCTYPE decl
BLOCK_SIZE
private static final int BLOCK_SIZE
- How many bytes to scan before giving up
- See Also:
- Constant Field Values
DocTypeDeclRemover
public DocTypeDeclRemover(InputStream in)
- Default constructor: records the input stream to filter.
read
public int read()
throws IOException
- See
the general contract of the
read
method of InputStream
.
- Overrides:
read
in class BufferedInputStream
- Returns:
- the next byte of data, or
-1
if the end of the
stream is reached.
- Throws:
IOException
- if an I/O error occurs.- See Also:
FilterInputStream.in
read
public int read(byte[] b,
int off,
int len)
throws IOException
- Read a block of bytes. The first
BLOCK_SIZE
bytes will be
scanned for a DOCTYPE declaration, and if one is found it will be
converted to an XML comment.
- Overrides:
read
in class BufferedInputStream
- Parameters:
b
- Buffer to read intooff
- Byte offset to read intolen
- Number of bytes to read
- Returns:
- Number of bytes read, or
-1
if the end of
the stream has been reached.
- Throws:
IOException
- if an I/O error occurs.
findEnd
private int findEnd(String s,
int start)