is new.
java.lang.Objectjava.beans.XMLDecoder
The 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.
| Constructor Summary | |
|---|---|
|
XMLDecoder
(
InputStream
in) Creates a new input stream for reading archives created by the XMLEncoder class. |
|
|
XMLDecoder
(
InputStream
in,
Object
owner) Creates a new input stream for reading archives created by the XMLEncoder class. |
|
|
XMLDecoder
(
InputStream
in,
Object
owner,
ExceptionListener
exceptionListener) Creates a new input stream for reading archives created by the XMLEncoder class. |
|
XMLDecoder
(
InputStream
in,
Object
owner,
ExceptionListener
exceptionListener,
ClassLoader
Creates a new input stream for reading archives created by the XMLEncoder class.
|
|
| Method Summary | |
|---|---|
| void |
close
() This method closes the input stream associated with this stream. |
ClassLoader
|
getClassLoader
()
Return the class loader used to instantiate objects.
|
| ExceptionListener |
getExceptionListener
() Gets the exception handler for this stream. |
| Object |
getOwner
() Gets the owner of this decoder. |
| Object |
readObject
() Reads the next object from the underlying input stream. |
void
|
setClassLoader
(
ClassLoader
Set the class loader used to instantiate objects for this stream.
|
| void |
setExceptionListener
(
ExceptionListener
exceptionListener) Sets the exception handler for this stream to exceptionListener. |
| void |
setOwner
(
Object
owner) Sets the owner of this decoder to owner. |
| Methods inherited from class java.lang. Object |
|---|
| clone , equals , finalize , getClass , hashCode , notify , notifyAll , toString , wait , wait , wait |
| Constructor Detail |
|---|
public XMLDecoder(InputStream in)
public XMLDecoder(InputStream in,
Object owner)
public XMLDecoder(InputStream in,
Object owner,
ExceptionListener exceptionListener)
exceptionListener - the exception handler for the stream; if null the default exception listener will be used.
XMLDecoder
public
XMLDecoder
(
InputStream
in,
Object
owner,
ExceptionListener
exceptionListener,
ClassLoader
cl)
Creates a new input stream for reading archives created by the XMLEncoder class.
Parameters:
in - the underlying stream
owner - the owner of this stream
exceptionListener - the exception handler for the stream
cl - the class loader used for instantiating objects
Since:
1.5
| Method Detail |
|---|
setClassLoader
public void
setClassLoader
(
ClassLoader
cl)
Set the class loader used to instantiate objects for this stream.
Parameters:
cl - a classloader to use; if null then the default class loader will be returned
Since:
1.5
getClassLoader
public
ClassLoader
getClassLoader
()
Return the class loader used to instantiate objects. If the class loader has not been explicitly set then the default class loader will be returned.
Returns:
the class loader used to instantiate objects
Since:
1.5
public void close()
public void setExceptionListener(ExceptionListener exceptionListener)
stream; if null the default exception listener will be used.
public ExceptionListener getExceptionListener()
Will return the default exception listener if this has not explicitly been set.
public Object readObject()
public void setOwner(Object owner)
public Object getOwner()