final class XmlReader
extends java.io.Reader
Note that the autodetection facility should be used only on data streams which have an unknown character encoding. For example, it should never be used on MIME text/xml entities.
Note that XML processors are only required to support UTF-8 and UTF-16 character encodings. Autodetection permits the underlying Java implementation to provide support for many other encodings, such as US-ASCII, ISO-8859-5, Shift_JIS, EUC-JP, and ISO-2022-JP.
| Modifier and Type | Class and Description |
|---|---|
(package private) static class |
XmlReader.AsciiReader |
(package private) static class |
XmlReader.BaseReader |
(package private) static class |
XmlReader.Iso8859_1Reader |
(package private) static class |
XmlReader.Utf8Reader |
| Modifier and Type | Field and Description |
|---|---|
private java.lang.String |
assignedEncoding |
private static java.util.Hashtable |
charsets |
private boolean |
closed |
private java.io.Reader |
in |
private static int |
MAXPUSHBACK |
| Modifier | Constructor and Description |
|---|---|
private |
XmlReader(java.io.InputStream stream) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the reader.
|
static java.io.Reader |
createReader(java.io.InputStream in)
Constructs the reader from an input stream, autodetecting
the encoding to use according to the heuristic specified
in the XML 1.0 recommendation.
|
static java.io.Reader |
createReader(java.io.InputStream in,
java.lang.String encoding)
Creates a reader supporting the given encoding, mapping
from standard encoding names to ones that understood by
Java where necessary.
|
java.lang.String |
getEncoding()
Returns the standard name of the encoding in use
|
void |
mark(int value)
Sets a mark allowing a limited number of characters to
be "peeked", by reading and then resetting.
|
boolean |
markSupported()
Returns true iff the reader supports mark/reset.
|
int |
read()
Reads a single character.
|
int |
read(char[] buf,
int off,
int len)
Reads the number of characters read into the buffer, or -1 on EOF.
|
boolean |
ready()
Returns true iff input characters are known to be ready.
|
void |
reset()
Resets the current position to the last marked position.
|
private void |
setEncoding(java.io.InputStream stream,
java.lang.String encoding) |
long |
skip(long value)
Skips a specified number of characters.
|
private static java.lang.String |
std2java(java.lang.String encoding) |
private void |
useEncodingDecl(java.io.PushbackInputStream pb,
java.lang.String encoding) |
private static final int MAXPUSHBACK
private java.io.Reader in
private java.lang.String assignedEncoding
private boolean closed
private static final java.util.Hashtable charsets
private XmlReader(java.io.InputStream stream)
throws java.io.IOException
java.io.IOExceptionpublic static java.io.Reader createReader(java.io.InputStream in)
throws java.io.IOException
in - the input stream from which the reader is constructedjava.io.IOException - on error, such as unrecognized encodingpublic static java.io.Reader createReader(java.io.InputStream in,
java.lang.String encoding)
throws java.io.IOException
in - the input stream from which the reader is constructedencoding - the IETF standard name of the encoding to use;
if null, autodetection is used.java.io.IOException - on error, including unrecognized encodingprivate static java.lang.String std2java(java.lang.String encoding)
public java.lang.String getEncoding()
private void useEncodingDecl(java.io.PushbackInputStream pb,
java.lang.String encoding)
throws java.io.IOException
java.io.IOExceptionprivate void setEncoding(java.io.InputStream stream,
java.lang.String encoding)
throws java.io.IOException
java.io.IOExceptionpublic int read(char[] buf,
int off,
int len)
throws java.io.IOException
read in class java.io.Readerjava.io.IOExceptionpublic int read()
throws java.io.IOException
read in class java.io.Readerjava.io.IOExceptionpublic boolean markSupported()
markSupported in class java.io.Readerpublic void mark(int value)
throws java.io.IOException
mark in class java.io.Readervalue - how many characters may be "peeked".java.io.IOExceptionpublic void reset()
throws java.io.IOException
reset in class java.io.Readerjava.io.IOExceptionpublic long skip(long value)
throws java.io.IOException
skip in class java.io.Readerjava.io.IOExceptionpublic boolean ready()
throws java.io.IOException
ready in class java.io.Readerjava.io.IOExceptionpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.Readerjava.io.IOException