Top Description Inners Fields Constructors Methods
com.sun.msv.scanner.dtd

pack-priv final Class XmlReader

extends Reader
Class Inheritance
Imports
java.io.ByteArrayInputStream, .CharConversionException, .IOException, .InputStream, .InputStreamReader, .PushbackInputStream, .Reader, java.util.HashMap

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.

Authors
David Brownell, Janet Koenig
Version
1.3 00/02/24

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv abstract static class
pack-priv static class
pack-priv static class

Field Summary

Modifier and TypeField and Description
private String
private static final HashMap<String, String>
private boolean
private Reader
private static final int
Inherited from java.io.Reader:
lock

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements abstract java.io.Reader.close.

Implements java.io.Closeable.close.

Closes the reader.
public static Reader
createReader(InputStream
the input stream from which the reader is constructed
in
)

Constructs the reader from an input stream, autodetecting the encoding to use according to the heuristic specified in the XML 1.0 recommendation.

public static Reader
createReader(InputStream
the input stream from which the reader is constructed
in
,
String
the IETF standard name of the encoding to use; if null, autodetection is used.
encoding
)

Creates a reader supporting the given encoding, mapping from standard encoding names to ones that understood by Java where necessary.

public String
getEncoding()

Returns the standard name of the encoding in use

public void
mark(int
how many characters may be "peeked".
value
)

Overrides java.io.Reader.mark.

Sets a mark allowing a limited number of characters to be "peeked", by reading and then resetting.
public boolean
markSupported()

Overrides java.io.Reader.markSupported.

Returns true iff the reader supports mark/reset.
public int
read(char[]
Destination buffer
buf
,
int
Offset at which to start storing characters
off
,
int
Maximum number of characters to read
len
)

Implements abstract java.io.Reader.read.

Reads the number of characters read into the buffer, or -1 on EOF.
public int
read()

Overrides java.io.Reader.read.

Reads a single character.
public boolean
ready()

Overrides java.io.Reader.ready.

Returns true iff input characters are known to be ready.
public void
reset()

Overrides java.io.Reader.reset.

Resets the current position to the last marked position.
private void
setEncoding(InputStream stream, String encoding)

public long
skip(long
The number of characters to skip
value
)

Overrides java.io.Reader.skip.

Skips a specified number of characters.
private static String
std2java(String encoding)

private void
Inherited from java.io.Reader:
nullReaderreadreadtransferTo

Field Detail

assignedEncodingback to summary
private String assignedEncoding
charsetsback to summary
private static final HashMap<String, String> charsets
closedback to summary
private boolean closed
inback to summary
private Reader in
MAXPUSHBACKback to summary
private static final int MAXPUSHBACK

Constructor Detail

XmlReaderback to summary
private XmlReader(InputStream stream) throws IOException

Method Detail

closeback to summary
public void close() throws IOException

Implements abstract java.io.Reader.close.

Implements java.io.Closeable.close.

Closes the reader.

Exceptions
IOException:

Doc from java.io.Reader.close.

If an I/O error occurs

createReaderback to summary
public static Reader createReader(InputStream in) throws IOException

Constructs the reader from an input stream, autodetecting the encoding to use according to the heuristic specified in the XML 1.0 recommendation.

Parameters
in:InputStream

the input stream from which the reader is constructed

Exceptions
IOException:
on error, such as unrecognized encoding
createReaderback to summary
public static Reader createReader(InputStream in, String encoding) throws IOException

Creates a reader supporting the given encoding, mapping from standard encoding names to ones that understood by Java where necessary.

Parameters
in:InputStream

the input stream from which the reader is constructed

encoding:String

the IETF standard name of the encoding to use; if null, autodetection is used.

Exceptions
IOException:
on error, including unrecognized encoding
getEncodingback to summary
public String getEncoding()

Returns the standard name of the encoding in use

markback to summary
public void mark(int value) throws IOException

Overrides java.io.Reader.mark.

Sets a mark allowing a limited number of characters to be "peeked", by reading and then resetting.

Parameters
value:int

how many characters may be "peeked".

Exceptions
IOException:

Doc from java.io.Reader.mark.

If the stream does not support mark(), or if some other I/O error occurs

markSupportedback to summary
public boolean markSupported()

Overrides java.io.Reader.markSupported.

Returns true iff the reader supports mark/reset.

Returns:boolean

Doc from java.io.Reader.markSupported.

true if and only if this stream supports the mark operation.

readback to summary
public int read(char[] buf, int off, int len) throws IOException

Implements abstract java.io.Reader.read.

Reads the number of characters read into the buffer, or -1 on EOF.

Parameters
buf:char[]

Doc from java.io.Reader.read.

Destination buffer

off:int

Doc from java.io.Reader.read.

Offset at which to start storing characters

len:int

Doc from java.io.Reader.read.

Maximum number of characters to read

Returns:int

Doc from java.io.Reader.read.

The number of characters read, or -1 if the end of the stream has been reached

Exceptions
IOException:

Doc from java.io.Reader.read.

If an I/O error occurs

readback to summary
public int read() throws IOException

Overrides java.io.Reader.read.

Reads a single character.

Returns:int

Doc from java.io.Reader.read.

The character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached

Exceptions
IOException:

Doc from java.io.Reader.read.

If an I/O error occurs

readyback to summary
public boolean ready() throws IOException

Overrides java.io.Reader.ready.

Returns true iff input characters are known to be ready.

Returns:boolean

Doc from java.io.Reader.ready.

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.

Exceptions
IOException:

Doc from java.io.Reader.ready.

If an I/O error occurs

resetback to summary
public void reset() throws IOException

Overrides java.io.Reader.reset.

Resets the current position to the last marked position.

Exceptions
IOException:

Doc from java.io.Reader.reset.

If the stream has not been marked, or if the mark has been invalidated, or if the stream does not support reset(), or if some other I/O error occurs

setEncodingback to summary
private void setEncoding(InputStream stream, String encoding) throws IOException
skipback to summary
public long skip(long value) throws IOException

Overrides java.io.Reader.skip.

Skips a specified number of characters.

Parameters
value:long

Doc from java.io.Reader.skip.

The number of characters to skip

Returns:long

Doc from java.io.Reader.skip.

The number of characters actually skipped

Exceptions
IOException:

Doc from java.io.Reader.skip.

If an I/O error occurs

std2javaback to summary
private static String std2java(String encoding)
useEncodingDeclback to summary
private void useEncodingDecl(PushbackInputStream pb, String encoding) throws IOException
com.sun.msv.scanner.dtd back to summary

pack-priv final Class XmlReader.AsciiReader

extends BaseReader
Class Inheritance

Field Summary

Inherited from com.sun.msv.scanner.dtd.XmlReader.BaseReader:
bufferfinishinstreamstart

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public int
read(char[]
Destination buffer
buf
,
int
Offset at which to start storing characters
offset
,
int
Maximum number of characters to read
len
)

Implements abstract java.io.Reader.read.

Reads characters into a portion of an array.
Inherited from com.sun.msv.scanner.dtd.XmlReader.BaseReader:
closeready

Constructor Detail

AsciiReaderback to summary
pack-priv AsciiReader(InputStream in)

Method Detail

readback to summary
public int read(char[] buf, int offset, int len) throws IOException

Implements abstract java.io.Reader.read.

Doc from java.io.Reader.read.

Reads characters into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.

If len is zero, then no characters are read and 0 is returned; otherwise, there is an attempt to read at least one character. If no character is available because the stream is at its end, the value -1 is returned; otherwise, at least one character is read and stored into cbuf.

Parameters
buf:char[]

Destination buffer

offset:int

Offset at which to start storing characters

len:int

Maximum number of characters to read

Returns:int

The number of characters read, or -1 if the end of the stream has been reached

Exceptions
IOException:
If an I/O error occurs
com.sun.msv.scanner.dtd back to summary

pack-priv abstract Class XmlReader.BaseReader

extends Reader
Class Inheritance
Known Direct Subclasses
com.sun.msv.scanner.dtd.XmlReader.Utf8Reader, com.sun.msv.scanner.dtd.XmlReader.AsciiReader, com.sun.msv.scanner.dtd.XmlReader.Iso8859_1Reader

Field Summary

Modifier and TypeField and Description
protected byte[]
protected int
protected InputStream
protected int
Inherited from java.io.Reader:
lock

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements abstract java.io.Reader.close.

Implements java.io.Closeable.close.

Closes the stream and releases any system resources associated with it.
public boolean
ready()

Overrides java.io.Reader.ready.

Tells whether this stream is ready to be read.
Inherited from java.io.Reader:
markmarkSupportednullReaderreadreadreadreadresetskiptransferTo

Field Detail

bufferback to summary
protected byte[] buffer
finishback to summary
protected int finish
instreamback to summary
protected InputStream instream
startback to summary
protected int start

Constructor Detail

BaseReaderback to summary
pack-priv BaseReader(InputStream stream)

Method Detail

closeback to summary
public void close() throws IOException

Implements abstract java.io.Reader.close.

Implements java.io.Closeable.close.

Doc from java.io.Reader.close.

Closes the stream and releases any system resources associated with it. Once the stream has been closed, further read(), ready(), mark(), reset(), or skip() invocations will throw an IOException. Closing a previously closed stream has no effect.

Exceptions
IOException:
If an I/O error occurs
readyback to summary
public boolean ready() throws IOException

Overrides java.io.Reader.ready.

Doc from java.io.Reader.ready.

Tells whether this stream is ready to be read.

Returns:boolean

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.

Exceptions
IOException:
If an I/O error occurs
com.sun.msv.scanner.dtd back to summary

pack-priv final Class XmlReader.Iso8859_1Reader

extends BaseReader
Class Inheritance

Field Summary

Inherited from com.sun.msv.scanner.dtd.XmlReader.BaseReader:
bufferfinishinstreamstart

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public int
read(char[]
Destination buffer
buf
,
int
Offset at which to start storing characters
offset
,
int
Maximum number of characters to read
len
)

Implements abstract java.io.Reader.read.

Reads characters into a portion of an array.
Inherited from com.sun.msv.scanner.dtd.XmlReader.BaseReader:
closeready

Constructor Detail

Iso8859_1Readerback to summary
pack-priv Iso8859_1Reader(InputStream in)

Method Detail

readback to summary
public int read(char[] buf, int offset, int len) throws IOException

Implements abstract java.io.Reader.read.

Doc from java.io.Reader.read.

Reads characters into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.

If len is zero, then no characters are read and 0 is returned; otherwise, there is an attempt to read at least one character. If no character is available because the stream is at its end, the value -1 is returned; otherwise, at least one character is read and stored into cbuf.

Parameters
buf:char[]

Destination buffer

offset:int

Offset at which to start storing characters

len:int

Maximum number of characters to read

Returns:int

The number of characters read, or -1 if the end of the stream has been reached

Exceptions
IOException:
If an I/O error occurs
com.sun.msv.scanner.dtd back to summary

pack-priv final Class XmlReader.Utf8Reader

extends BaseReader
Class Inheritance

Field Summary

Modifier and TypeField and Description
private char
Inherited from com.sun.msv.scanner.dtd.XmlReader.BaseReader:
bufferfinishinstreamstart

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public int
read(char[]
Destination buffer
buf
,
int
Offset at which to start storing characters
offset
,
int
Maximum number of characters to read
len
)

Implements abstract java.io.Reader.read.

Reads characters into a portion of an array.
Inherited from com.sun.msv.scanner.dtd.XmlReader.BaseReader:
closeready

Field Detail

nextCharback to summary
private char nextChar

Constructor Detail

Utf8Readerback to summary
pack-priv Utf8Reader(InputStream stream)

Method Detail

readback to summary
public int read(char[] buf, int offset, int len) throws IOException

Implements abstract java.io.Reader.read.

Doc from java.io.Reader.read.

Reads characters into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.

If len is zero, then no characters are read and 0 is returned; otherwise, there is an attempt to read at least one character. If no character is available because the stream is at its end, the value -1 is returned; otherwise, at least one character is read and stored into cbuf.

Parameters
buf:char[]

Destination buffer

offset:int

Offset at which to start storing characters

len:int

Maximum number of characters to read

Returns:int

The number of characters read, or -1 if the end of the stream has been reached

Exceptions
IOException:
If an I/O error occurs