Package com.sun.java.help.impl
Class XmlReader
- java.lang.Object
-
- java.io.Reader
-
- com.sun.java.help.impl.XmlReader
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.lang.Readable
public final class XmlReader extends java.io.ReaderThis 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 ISO-8859-5, Shift_JIS, EUC-JP, and ISO-2022-JP.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the reader.static java.io.ReadercreateReader(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.ReadercreateReader(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.static java.io.ReadercreateReader(java.net.URLConnection uc)Constructs the reader from a URLConnection.java.lang.StringgetEncoding()Returns the (non)standard name of the encoding in usevoidmark(int value)Sets a mark allowing a limited number of characters to be "peeked", by reading and then resetting.booleanmarkSupported()Returns true iff the reader supports mark/reset.intread()Reads a single character.intread(char[] buf, int off, int len)Reads the number of characters read into the buffer, or -1 on EOF.booleanready()Returns true iff input characters are known to be ready.voidreset()Resets the current position to the last marked position.longskip(long value)Skips a specified number of characters.
-
-
-
Method Detail
-
createReader
public static java.io.Reader createReader(java.net.URLConnection uc) throws java.io.IOExceptionConstructs the reader from a URLConnection. Uses the encoding specified in the HTTP header or autodetects the encoding to use according to the heuristic specified in the XML 1.0 recommendation.- Parameters:
uc- the URLConnection from which the reader is constructed- Throws:
java.io.IOException- on errorjava.io.UnsupportedEncodingException- when the input stream is not in an encoding which is supported; this is a fatal XML error.
-
createReader
public static java.io.Reader createReader(java.io.InputStream in) throws java.io.IOExceptionConstructs the reader from an input stream, autodetecting 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:
java.io.IOException- on errorjava.io.UnsupportedEncodingException- when the input stream is not in an encoding which is supported; this is a fatal XML error.
-
createReader
public static java.io.Reader createReader(java.io.InputStream in, java.lang.String encoding) throws java.io.IOExceptionCreates 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, autodetection is used.- Throws:
java.io.IOException- on errorjava.io.UnsupportedEncodingException- when the input stream is not in an encoding which is supported; this is a fatal XML error.
-
getEncoding
public java.lang.String getEncoding()
Returns the (non)standard name of the encoding in use
-
read
public int read(char[] buf, int off, int len) throws java.io.IOExceptionReads the number of characters read into the buffer, or -1 on EOF.- Specified by:
readin classjava.io.Reader- Throws:
java.io.IOException
-
read
public int read() throws java.io.IOExceptionReads a single character.- Overrides:
readin classjava.io.Reader- Throws:
java.io.IOException
-
markSupported
public boolean markSupported()
Returns true iff the reader supports mark/reset.- Overrides:
markSupportedin classjava.io.Reader
-
mark
public void mark(int value) throws java.io.IOExceptionSets a mark allowing a limited number of characters to be "peeked", by reading and then resetting.- Overrides:
markin classjava.io.Reader- Parameters:
value- how many characters may be "peeked".- Throws:
java.io.IOException
-
reset
public void reset() throws java.io.IOExceptionResets the current position to the last marked position.- Overrides:
resetin classjava.io.Reader- Throws:
java.io.IOException
-
skip
public long skip(long value) throws java.io.IOExceptionSkips a specified number of characters.- Overrides:
skipin classjava.io.Reader- Throws:
java.io.IOException
-
ready
public boolean ready() throws java.io.IOExceptionReturns true iff input characters are known to be ready.- Overrides:
readyin classjava.io.Reader- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOExceptionCloses the reader.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classjava.io.Reader- Throws:
java.io.IOException
-
-