public abstract class Source
extends java.io.Reader
implements java.io.Serializable
new InputStreamReader (connection.getInputStream (), charset)It differs from the above, in three ways:
限定符和类型 | 字段和说明 |
---|---|
static int |
EOF
Return value when the source is exhausted.
|
构造器和说明 |
---|
Source() |
限定符和类型 | 方法和说明 |
---|---|
abstract int |
available()
Get the number of available characters.
|
abstract void |
close()
Does nothing.
|
abstract void |
destroy()
Close the source.
|
abstract char |
getCharacter(int offset)
Retrieve a character again.
|
abstract void |
getCharacters(char[] array,
int offset,
int start,
int end)
Retrieve characters again.
|
abstract void |
getCharacters(java.lang.StringBuffer buffer,
int offset,
int length)
Append characters already read into a
StringBuffer . |
abstract java.lang.String |
getEncoding()
Get the encoding being used to convert characters.
|
abstract java.lang.String |
getString(int offset,
int length)
Retrieve a string comprised of characters already read.
|
abstract void |
mark(int readAheadLimit)
Mark the present position.
|
abstract boolean |
markSupported()
Tell whether this source supports the mark() operation.
|
abstract int |
offset()
Get the position (in characters).
|
abstract int |
read()
Read a single character.
|
abstract int |
read(char[] cbuf)
Read characters into an array.
|
abstract int |
read(char[] cbuf,
int off,
int len)
Read characters into a portion of an array.
|
abstract boolean |
ready()
Tell whether this source is ready to be read.
|
abstract void |
reset()
Reset the source.
|
abstract void |
setEncoding(java.lang.String character_set)
Set the encoding to the given character set.
|
abstract long |
skip(long n)
Skip characters.
|
abstract void |
unread()
Undo the read of a single character.
|
public static final int EOF
public abstract java.lang.String getEncoding()
public abstract void setEncoding(java.lang.String character_set) throws ParserException
If characters have already been consumed from this source, it is expected that an exception will be thrown if the characters read so far would be different if the encoding being set was used from the start.
character_set
- The character set to use to convert 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 character set is not recognized.public abstract void close() throws java.io.IOException
destroy()
instead.close
在接口中 java.io.Closeable
close
在接口中 java.lang.AutoCloseable
close
在类中 java.io.Reader
java.io.IOException
- not useddestroy()
public abstract int read() throws java.io.IOException
read
在类中 java.io.Reader
EOF
if the source is exhausted.java.io.IOException
- If an I/O error occurs.public abstract int read(char[] cbuf, int off, int len) throws java.io.IOException
read
在类中 java.io.Reader
cbuf
- Destination bufferoff
- Offset at which to start storing characterslen
- Maximum number of characters to readEOF
if the source is
exhausted.java.io.IOException
- If an I/O error occurs.public abstract int read(char[] cbuf) throws java.io.IOException
read
在类中 java.io.Reader
cbuf
- Destination buffer.EOF
if the source is
exhausted.java.io.IOException
- If an I/O error occurs.public abstract boolean ready() throws java.io.IOException
ready
在类中 java.io.Reader
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.java.io.IOException
- If an I/O error occurs.public abstract void reset()
reset
在类中 java.io.Reader
public abstract boolean markSupported()
markSupported
在类中 java.io.Reader
true
if and only if this source supports the mark
operation.public abstract void mark(int readAheadLimit) throws java.io.IOException
reset()
will attempt to reposition the source to this point. Not all
sources support the mark() operation.mark
在类中 java.io.Reader
readAheadLimit
- The minimum number of characters that can be read
before this mark becomes invalid.java.io.IOException
- If an I/O error occurs.public abstract long skip(long n) throws java.io.IOException
skip
在类中 java.io.Reader
n
- The number of characters to skip.java.io.IOException
- If an I/O error occurs.public abstract void unread() throws java.io.IOException
java.io.IOException
- If the source is closed or no characters have
been read.public abstract char getCharacter(int offset) throws java.io.IOException
offset
- The offset of the character.offset
.java.io.IOException
- If the source is closed or the offset is beyond
offset()
.public abstract void getCharacters(char[] array, int offset, int start, int end) throws java.io.IOException
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 the start or end is
beyond offset()
.public abstract java.lang.String getString(int offset, int length) throws java.io.IOException
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.public abstract void getCharacters(java.lang.StringBuffer buffer, int offset, int length) throws java.io.IOException
StringBuffer
.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 the offset or
(offset + length) is beyond offset()
.public abstract 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.java.io.IOException
- If an I/O error occurs.public abstract int offset()
EOF
if the source is closed.public abstract int available()