XMLDecoderpublic class XMLDecoder extends Object 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. |
Fields Summary |
---|
private InputStream | in | private Object | owner | private ExceptionListener | exceptionListener | private com.sun.beans.ObjectHandler | handler | private Reference | clref |
Constructors Summary |
---|
public XMLDecoder(InputStream in)Creates a new input stream for reading archives
created by the XMLEncoder class.
this(in, null);
| public XMLDecoder(InputStream in, Object owner)Creates a new input stream for reading archives
created by the XMLEncoder class.
this(in, owner, null);
| public XMLDecoder(InputStream in, Object owner, ExceptionListener exceptionListener)Creates a new input stream for reading archives
created by the XMLEncoder class.
this(in, owner, exceptionListener, null);
| public XMLDecoder(InputStream in, Object owner, ExceptionListener exceptionListener, ClassLoader cl)Creates a new input stream for reading archives
created by the XMLEncoder class.
this.in = in;
setOwner(owner);
setExceptionListener(exceptionListener);
setClassLoader(cl);
|
Methods Summary |
---|
public void | close()This method closes the input stream associated
with this stream.
if (in != null) {
try {
in.close();
}
catch (IOException e) {
getExceptionListener().exceptionThrown(e);
}
}
| private java.lang.ClassLoader | getClassLoader()Return the class loader used to instantiate objects. If the class loader
has not been explicitly set then null is returned.
if (clref != null) {
return (ClassLoader)clref.get();
}
return null;
| public java.beans.ExceptionListener | getExceptionListener()Gets the exception handler for this stream.
return (exceptionListener != null) ? exceptionListener :
Statement.defaultExceptionListener;
| public java.lang.Object | getOwner()Gets the owner of this decoder.
return owner;
| public java.lang.Object | readObject()Reads the next object from the underlying input stream.
if (in == null) {
return null;
}
if (handler == null) {
SAXParserFactory factory = SAXParserFactory.newInstance();
try {
SAXParser saxParser = factory.newSAXParser();
handler = new ObjectHandler(this, getClassLoader());
saxParser.parse(in, handler);
}
catch (ParserConfigurationException e) {
getExceptionListener().exceptionThrown(e);
}
catch (SAXException se) {
Exception e = se.getException();
getExceptionListener().exceptionThrown((e == null) ? se : e);
}
catch (IOException ioe) {
getExceptionListener().exceptionThrown(ioe);
}
}
return handler.dequeueResult();
| private void | setClassLoader(java.lang.ClassLoader cl)Set the class loader used to instantiate objects for this stream.
if (cl != null) {
this.clref = new WeakReference(cl);
}
| public void | setExceptionListener(java.beans.ExceptionListener exceptionListener)Sets the exception handler for this stream to exceptionListener .
The exception handler is notified when this stream catches recoverable
exceptions.
this.exceptionListener = exceptionListener;
| public void | setOwner(java.lang.Object owner)Sets the owner of this decoder to owner .
this.owner = owner;
|
|