org.htmlparser.lexer
public class InputStreamSource extends Source
Field Summary | |
---|---|
static int | BUFFER_SIZE
An initial buffer size.
|
protected char[] | mBuffer
The characters read so far. |
protected 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 InputStreamReader | mReader
The converter from bytes to characters. |
protected InputStream | mStream
The stream of bytes.
|
Constructor Summary | |
---|---|
InputStreamSource(InputStream stream)
Create a source of characters using the default character set. | |
InputStreamSource(InputStream stream, String charset)
Create a source of characters. | |
InputStreamSource(InputStream stream, 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(StringBuffer buffer, int offset, int length)
Append characters already read into a StringBuffer . |
String | getEncoding()
Get the encoding being used to convert characters. |
InputStream | getStream()
Get the input stream being used. |
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, int off, int len)
Read characters into a portion of an array. |
int | read(char[] cbuf)
Read characters into an array.
|
boolean | ready()
Tell whether this source is ready to be read. |
void | reset()
Reset the source.
|
void | setEncoding(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. |
null
when the source is closed.Parameters: stream The stream of bytes to use.
Throws: UnsupportedEncodingException If the default character set is unsupported.
Parameters: stream The stream of bytes to use. charset The character set used in encoding the stream.
Throws: UnsupportedEncodingException If the character set is unsupported.
Parameters: stream The stream of bytes to use. charset The character set used in encoding the stream. size The initial character buffer size.
Throws: UnsupportedEncodingException If the character set is unsupported.
Returns: The number of characters that can be read without blocking or zero if the source is closed.
Throws: IOException not used
See Also: InputStreamSource
read
,
ready
, mark
, reset
,
skip
, unread
,
getCharacter
or getString
invocations will throw an IOException.
Closing a previously-closed source, however, has no effect.Throws: IOException If an I/O error occurs
Parameters: min The minimum to read.
Throws: IOException If the underlying reader read() throws one.
Parameters: offset The offset of the character.
Returns: The character at offset
.
Throws: IOException If the offset is beyond offset or the source is closed.
Parameters: array 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.
Throws: IOException If the start or end is beyond offset or the source is closed.
StringBuffer
.Parameters: buffer The buffer to append to. offset The offset of the first character. length The number of characters to retrieve.
Throws: IOException If the offset or (offset + length) is beyond offset or the source is closed.
Returns: The current encoding.
Returns: The current input stream.
Parameters: offset The offset of the first character. length The number of characters to retrieve.
Returns: A string containing the length
characters at offset
.
Throws: IOException If the offset or (offset + length) is beyond offset or the source is closed.
Parameters: readAheadLimit Not used.
Throws: IOException If the source is closed.
Returns: true
.
Returns: The number of characters that have already been read, or
EOF
if the source is closed.
Returns: The character read, as an integer in the range 0 to 65535
(0x00-0xffff), or EOF
if the end of the stream has
been reached
Throws: IOException If an I/O error occurs.
Parameters: cbuf Destination buffer off Offset at which to start storing characters len Maximum number of characters to read
Returns: The number of characters read, or EOF
if the end of
the stream has been reached
Throws: IOException If an I/O error occurs.
Parameters: cbuf Destination buffer.
Returns: The number of characters read, or EOF
if the end of
the stream has been reached.
Throws: IOException If an I/O error occurs.
Returns: true
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.
Throws: IOException If the source is closed.
Throws: IllegalStateException If the source has been closed.
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.
Parameters: character_set The character set to use to convert bytes into characters.
Throws: 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.
Parameters: n The number of characters to skip.
Returns: The number of characters actually skipped
Throws: IllegalArgumentException If n
is negative. IOException If an I/O error occurs.
Throws: IOException If the source is closed or no characters have been read.
HTML Parser is an open source library released under LGPL. | |