public class StringSource extends Source
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
mEncoding
The encoding to report.
|
protected int |
mMark
The bookmark.
|
protected int |
mOffset
The current offset into the string.
|
protected java.lang.String |
mString
The source of characters.
|
Constructor and Description |
---|
StringSource(java.lang.String string)
Construct a source using the provided string.
|
StringSource(java.lang.String string,
java.lang.String character_set)
Construct a source using the provided string and encoding.
|
Modifier and Type | Method and Description |
---|---|
int |
available()
Get the number of available characters.
|
void |
close()
Does nothing.
|
void |
destroy()
Close the source.
|
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.lang.String |
getString(int offset,
int length)
Retrieve a string comprised of characters already read.
|
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)
Set the encoding to the given character set.
|
long |
skip(long n)
Skip characters.
|
void |
unread()
Undo the read of a single character.
|
protected java.lang.String mString
protected int mOffset
protected java.lang.String mEncoding
getEncoding()
.protected int mMark
public StringSource(java.lang.String string)
string
- The source of characters.public StringSource(java.lang.String string, java.lang.String character_set)
getEncoding()
.string
- The source of characters.character_set
- The encoding to report.public java.lang.String getEncoding()
getEncoding
in class Source
public void setEncoding(java.lang.String character_set) throws ParserException
getEncoding()
.setEncoding
in class Source
character_set
- The character set to use to convert characters.ParserException
- Not thrown.public void close() throws java.io.IOException
public int read() throws java.io.IOException
public int read(char[] cbuf, int off, int len) throws java.io.IOException
public int read(char[] cbuf) throws java.io.IOException
public boolean ready() throws java.io.IOException
ready
in class Source
available()
, i.e. there are
still more characters to read.java.io.IOException
- Thrown if the source is closed.public void reset() throws java.lang.IllegalStateException
public boolean markSupported()
markSupported
in class Source
true
.public void mark(int readAheadLimit) throws java.io.IOException
reset()
will attempt to reposition the source to this point.public long skip(long n) throws java.io.IOException, java.lang.IllegalArgumentException
public void unread() throws java.io.IOException
public char getCharacter(int offset) throws java.io.IOException
getCharacter
in class Source
offset
- The offset of the character.offset
.java.io.IOException
- If the source is closed or an attempt is made to
read beyond offset()
.public void getCharacters(char[] array, int offset, int start, int end) throws java.io.IOException
getCharacters
in class Source
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.java.io.IOException
- If the source is closed or an attempt is made to
read beyond offset()
.public java.lang.String getString(int offset, int length) throws java.io.IOException
offset()
will throw an exception.getString
in class Source
offset
- The offset of the first character.length
- The number of characters to retrieve.length
characters at offset
.java.io.IOException
- If the source is closed or an attempt is made to
read beyond offset()
.public void getCharacters(java.lang.StringBuffer buffer, int offset, int length) throws java.io.IOException
StringBuffer
.
Asking for characters ahead of offset()
will throw an exception.getCharacters
in class Source
buffer
- The buffer to append to.offset
- The offset of the first character.length
- The number of characters to retrieve.java.io.IOException
- If the source is closed or an attempt is made to
read beyond offset()
.public void destroy() throws java.io.IOException
public int offset()
HTML Parser is an open source library released under LGPL.