Package com.sun.xml.dtdparser
Class XmlReader
java.lang.Object
java.io.Reader
com.sun.xml.dtdparser.XmlReader
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Readable
This handles several XML-related tasks that normal java.io Readers
don't support, inluding use of IETF standard encoding names and
automatic detection of most XML encodings. The former is needed
for interoperability; the latter is needed to conform with the XML
spec. This class also optimizes reading some common encodings by
providing low-overhead unsynchronized Reader support.
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.
- Version:
- 1.3 00/02/24
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class
(package private) static class
(package private) static final class
(package private) static final class
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the reader.static Reader
Constructs the reader from an input stream, auto-detecting the encoding to use according to the heuristic specified in the XML 1.0 recommendation.static Reader
createReader
(InputStream in, String encoding) Creates a reader supporting the given encoding, mapping from standard encoding names to ones that understood by Java where necessary.Returns the standard name of the encoding in usevoid
mark
(int value) Sets a mark allowing a limited number of characters to be "peeked", by reading and then resetting.boolean
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
(InputStream stream, String encoding) long
skip
(long value) Skips a specified number of characters.private static String
private void
useEncodingDecl
(PushbackInputStream pb, String encoding) Methods inherited from class java.io.Reader
nullReader, read, read, transferTo
-
Field Details
-
MAXPUSHBACK
private static final int MAXPUSHBACK- See Also:
-
in
-
assignedEncoding
-
closed
private boolean closed -
charsets
-
-
Constructor Details
-
XmlReader
- Throws:
IOException
-
-
Method Details
-
createReader
Constructs the reader from an input stream, auto-detecting the encoding to use according to the heuristic specified in the XML 1.0 recommendation.- Parameters:
in
- the input stream from which the reader is constructed- Throws:
IOException
- on error, such as unrecognized encoding
-
createReader
Creates a reader supporting the given encoding, mapping from standard encoding names to ones that understood by Java where necessary.- Parameters:
in
- the input stream from which the reader is constructedencoding
- the IETF standard name of the encoding to use; if null, auto-detection is used.- Throws:
IOException
- on error, including unrecognized encoding
-
std2java
-
getEncoding
Returns the standard name of the encoding in use -
useEncodingDecl
- Throws:
IOException
-
setEncoding
- Throws:
IOException
-
read
Reads the number of characters read into the buffer, or -1 on EOF.- Specified by:
read
in classReader
- Throws:
IOException
-
read
Reads a single character.- Overrides:
read
in classReader
- Throws:
IOException
-
markSupported
public boolean markSupported()Returns true iff the reader supports mark/reset.- Overrides:
markSupported
in classReader
-
mark
Sets a mark allowing a limited number of characters to be "peeked", by reading and then resetting.- Overrides:
mark
in classReader
- Parameters:
value
- how many characters may be "peeked".- Throws:
IOException
-
reset
Resets the current position to the last marked position.- Overrides:
reset
in classReader
- Throws:
IOException
-
skip
Skips a specified number of characters.- Overrides:
skip
in classReader
- Throws:
IOException
-
ready
Returns true iff input characters are known to be ready.- Overrides:
ready
in classReader
- Throws:
IOException
-
close
Closes the reader.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classReader
- Throws:
IOException
-