XMLDecoder class is used to read XML documents
created using the XMLEncoder and is used just like
the ObjectInputStream. For example, one can use
the following fragment to read the first object defined
in an XML document written by the XMLEncoder
class:
XMLDecoder d = new XMLDecoder(
new BufferedInputStream(
new FileInputStream("Test.xml")));
Object result = d.readObject();
d.close();
For more information you might also want to check out Long Term Persistence of JavaBeans Components: XML Schema, an article in The Swing Connection.
XMLEncoder, java.io.ObjectInputStream
| Modifier and Type | Field and Description |
|---|---|
| private Object[] | |
| private final DocumentHandler | |
| private int | |
| private final InputSource | |
| private Object |
| Access | Constructor and Description |
|---|---|
| public | XMLDecoder(InputStream
The underlying stream. in)Creates a new input stream for reading archives
created by the |
| public | XMLDecoder(InputStream
The underlying stream. in, Object The owner of this stream. owner)Creates a new input stream for reading archives
created by the |
| public | XMLDecoder(InputStream
the underlying stream. in, Object the owner of this stream. owner, ExceptionListener the exception handler for the stream;
if exceptionListener)null the default exception listener will be used.Creates a new input stream for reading archives
created by the |
| public | XMLDecoder(InputStream
the underlying stream. in, Object null may be passed without
error, though the resulting XMLDecoder will be uselessthe owner of this stream. owner, ExceptionListener null is a legal
valuethe exception handler for the stream, or
exceptionListener, ClassLoader null to use the defaultthe class loader used for instantiating objects.
cl)null indicates that the default class loader should
be usedCreates a new input stream for reading archives
created by the |
| public | XMLDecoder(InputSource
the input source to parse is)Creates a new decoder to parse XML archives
created by the |
| private | XMLDecoder(InputSource
the input source to parse is, Object the owner of this decoder owner, ExceptionListener the exception handler for the parser,
or el, ClassLoader null to use the default exception handlerthe class loader used for instantiating objects,
or cl)null to use the default class loaderCreates a new decoder to parse XML archives
created by the |
| Modifier and Type | Method and Description |
|---|---|
| public void | close()
Implements java. This method closes the input stream associated with this stream. |
| private void | |
| public static DefaultHandler | Returns: an instance ofDefaultHandler for SAX parserthe owner of the default handler
that can be used as a value of <java> element owner, ExceptionListener the exception handler for the parser,
or el, ClassLoader null to use the default exception handlerthe class loader used for instantiating objects,
or cl)null to use the default class loaderCreates a new handler for SAX parser
that can be used to parse embedded XML archives
created by the |
| public ExceptionListener | Returns: The exception handler for this stream. Will return the default exception listener if this has not explicitly been set.Gets the exception handler for this stream. |
| public Object | |
| private boolean | |
| public Object | |
| public void | setExceptionListener(ExceptionListener
The exception handler for this stream;
if exceptionListener)null the default exception listener will be used.Sets the exception handler for this stream to |
| public void |
| array | back to summary |
|---|---|
| private Object[] array | |
| handler | back to summary |
|---|---|
| private final DocumentHandler handler | |
| index | back to summary |
|---|---|
| private int index | |
| input | back to summary |
|---|---|
| private final InputSource input | |
| owner | back to summary |
|---|---|
| private Object owner | |
| XMLDecoder | back to summary |
|---|---|
| public XMLDecoder(InputStream in) Creates a new input stream for reading archives
created by the
| |
| XMLDecoder | back to summary |
|---|---|
| public XMLDecoder(InputStream in, Object owner) Creates a new input stream for reading archives
created by the
| |
| XMLDecoder | back to summary |
|---|---|
| public XMLDecoder(InputStream in, Object owner, ExceptionListener exceptionListener) Creates a new input stream for reading archives
created by the
| |
| XMLDecoder | back to summary |
|---|---|
| public XMLDecoder(InputStream in, Object owner, ExceptionListener exceptionListener, ClassLoader cl) Creates a new input stream for reading archives
created by the
| |
| XMLDecoder | back to summary |
|---|---|
| public XMLDecoder(InputSource is) Creates a new decoder to parse XML archives
created by the
| |
| XMLDecoder | back to summary |
|---|---|
| private XMLDecoder(InputSource is, Object owner, ExceptionListener el, ClassLoader cl) Creates a new decoder to parse XML archives
created by the
| |
| close | back to summary |
|---|---|
| public void close() Implements java. This method closes the input stream associated with this stream.
| |
| close | back to summary |
|---|---|
| private void close(Closeable in) | |
| createHandler | back to summary |
|---|---|
| public static DefaultHandler createHandler(Object owner, ExceptionListener el, ClassLoader cl) Creates a new handler for SAX parser
that can be used to parse embedded XML archives
created by the
| |
| getExceptionListener | back to summary |
|---|---|
| public ExceptionListener getExceptionListener() Gets the exception handler for this stream.
| |
| getOwner | back to summary |
|---|---|
| public Object getOwner() Gets the owner of this decoder. | |
| parsingComplete | back to summary |
|---|---|
| private boolean parsingComplete() | |
| readObject | back to summary |
|---|---|
| public Object readObject() Reads the next object from the underlying input stream.
| |
| setExceptionListener | back to summary |
|---|---|
| public void setExceptionListener(ExceptionListener exceptionListener) Sets the exception handler for this stream to
| |
| setOwner | back to summary |
|---|---|
| public void setOwner(Object owner) Sets the owner of this decoder to | |