|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectjava.io.Reader
org.htmlparser.lexer.Source
org.htmlparser.lexer.InputStreamSource
A source of characters based on an InputStream such as from a URLConnection.
| Field Summary | |
static int |
BUFFER_SIZE
An initial buffer size. |
protected char[] |
mBuffer
The characters read so far. |
protected java.lang.String |
mEncoding
The character set in use. |
protected int |
mLevel
The number of valid bytes in the buffer. |
protected int |
mMark
The bookmark. |
protected int |
mOffset
The offset of the next byte returned by read(). |
protected java.io.InputStreamReader |
mReader
The converter from bytes to characters. |
protected java.io.InputStream |
mStream
The stream of bytes. |
| Fields inherited from class org.htmlparser.lexer.Source |
EOF |
| Fields inherited from class java.io.Reader |
lock |
| Constructor Summary | |
InputStreamSource(java.io.InputStream stream)
Create a source of characters using the default character set. |
|
InputStreamSource(java.io.InputStream stream,
java.lang.String charset)
Create a source of characters. |
|
InputStreamSource(java.io.InputStream stream,
java.lang.String charset,
int size)
Create a source of characters. |
|
| Method Summary | |
int |
available()
Get the number of available characters. |
void |
close()
Does nothing. |
void |
destroy()
Close the source. |
protected void |
fill(int min)
Fetch more characters from the underlying reader. |
char |
getCharacter(int offset)
Retrieve a character again. |
void |
getCharacters(char[] array,
int offset,
int start,
int end)
Retrieve characters again. |
void |
getCharacters(java.lang.StringBuffer buffer,
int offset,
int length)
Append characters already read into a StringBuffer. |
java.lang.String |
getEncoding()
Get the encoding being used to convert characters. |
java.io.InputStream |
getStream()
Get the input stream being used. |
java.lang.String |
getString(int offset,
int length)
Retrieve a string. |
void |
mark(int readAheadLimit)
Mark the present position in the source. |
boolean |
markSupported()
Tell whether this source supports the mark() operation. |
int |
offset()
Get the position (in characters). |
int |
read()
Read a single character. |
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()
Tell whether this source is ready to be read. |
void |
reset()
Reset the source. |
void |
setEncoding(java.lang.String character_set)
Begins reading from the source with the given character set. |
long |
skip(long n)
Skip characters. |
void |
unread()
Undo the read of a single character. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static int BUFFER_SIZE
protected transient java.io.InputStream mStream
null when the source is closed.
protected java.lang.String mEncoding
protected transient java.io.InputStreamReader mReader
protected char[] mBuffer
protected int mLevel
protected int mOffset
protected int mMark
| Constructor Detail |
public InputStreamSource(java.io.InputStream stream)
throws java.io.UnsupportedEncodingException
stream - The stream of bytes to use.
java.io.UnsupportedEncodingException - If the default character set
is unsupported.
public InputStreamSource(java.io.InputStream stream,
java.lang.String charset)
throws java.io.UnsupportedEncodingException
stream - The stream of bytes to use.charset - The character set used in encoding the stream.
java.io.UnsupportedEncodingException - If the character set
is unsupported.
public InputStreamSource(java.io.InputStream stream,
java.lang.String charset,
int size)
throws java.io.UnsupportedEncodingException
stream - The stream of bytes to use.charset - The character set used in encoding the stream.size - The initial character buffer size.
java.io.UnsupportedEncodingException - If the character set
is unsupported.| Method Detail |
public java.io.InputStream getStream()
public java.lang.String getEncoding()
getEncoding in class Source
public void setEncoding(java.lang.String character_set)
throws ParserException
Some magic happens here to obtain this result if characters have already been consumed from this source. Since a Reader cannot be dynamically altered to use a different character set, the underlying stream is reset, a new Source is constructed and a comparison made of the characters read so far with the newly read characters up to the current position. If a difference is encountered, or some other problem occurs, an exception is thrown.
setEncoding in class Sourcecharacter_set - The character set to use to convert bytes into
characters.
ParserException - If a character mismatch occurs between
characters already provided and those that would have been returned
had the new character set been in effect from the beginning. An
exception is also thrown if the underlying stream won't put up with
these shenanigans.
protected void fill(int min)
throws java.io.IOException
min - The minimum to read.
java.io.IOException - If the underlying reader read() throws one.
public void close()
throws java.io.IOException
close in class Sourcejava.io.IOException - not useddestroy()
public int read()
throws java.io.IOException
read in class SourceEOF if the end of the stream has
been reached
java.io.IOException - If an I/O error occurs.
public int read(char[] cbuf,
int off,
int len)
throws java.io.IOException
read in class Sourcecbuf - Destination bufferoff - Offset at which to start storing characterslen - Maximum number of characters to read
EOF if the end of
the stream has been reached
java.io.IOException - If an I/O error occurs.
public int read(char[] cbuf)
throws java.io.IOException
read in class Sourcecbuf - Destination buffer.
EOF if the end of
the stream has been reached.
java.io.IOException - If an I/O error occurs.
public void reset()
throws java.lang.IllegalStateException
reset in class Sourcejava.lang.IllegalStateException - If the source has been closed.public boolean markSupported()
markSupported in class Sourcetrue.
public void mark(int readAheadLimit)
throws java.io.IOException
reset()
will attempt to reposition the source to this point.
mark in class SourcereadAheadLimit - Not used.
java.io.IOException - If the source is closed.
public boolean ready()
throws java.io.IOException
ready in class Sourcetrue if the next read() is guaranteed not to block
for input, false otherwise.
Note that returning false does not guarantee that the next read will block.
java.io.IOException - If the source is closed.
public long skip(long n)
throws java.io.IOException,
java.lang.IllegalArgumentException
skip in class Sourcen - The number of characters to skip.
java.lang.IllegalArgumentException - If n is negative.
java.io.IOException - If an I/O error occurs.
public void unread()
throws java.io.IOException
unread in class Sourcejava.io.IOException - If the source is closed or no characters have
been read.
public char getCharacter(int offset)
throws java.io.IOException
getCharacter in class Sourceoffset - The offset of the character.
offset.
java.io.IOException - If the offset is beyond offset() or the
source is closed.
public void getCharacters(char[] array,
int offset,
int start,
int end)
throws java.io.IOException
getCharacters in class Sourcearray - The array of characters.offset - The starting position in the array where characters are to be placed.start - The starting position, zero based.end - The ending position
(exclusive, i.e. the character at the ending position is not included),
zero based.
java.io.IOException - If the start or end is beyond offset()
or the source is closed.
public java.lang.String getString(int offset,
int length)
throws java.io.IOException
getString in class Sourceoffset - The offset of the first character.length - The number of characters to retrieve.
length characters at offset.
java.io.IOException - If the offset or (offset + length) is beyond
offset() or the source is closed.
public void getCharacters(java.lang.StringBuffer buffer,
int offset,
int length)
throws java.io.IOException
StringBuffer.
getCharacters in class Sourcebuffer - The buffer to append to.offset - The offset of the first character.length - The number of characters to retrieve.
java.io.IOException - If the offset or (offset + length) is beyond
offset() or the source is closed.
public void destroy()
throws java.io.IOException
read,
ready, mark, reset,
skip, unread,
getCharacter or getString
invocations will throw an IOException.
Closing a previously-closed source, however, has no effect.
destroy in class Sourcejava.io.IOException - If an I/O error occurspublic int offset()
offset in class SourceEOF if the source is closed.public int available()
available in class Source
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||