AutoCloseablepublic class XMLDecoder extends Object implements AutoCloseable
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 | Description | 
|---|---|
| XMLDecoder | Creates a new input stream for reading archives created by the  XMLEncoderclass. | 
| XMLDecoder | Creates a new input stream for reading archives created by the  XMLEncoderclass. | 
| XMLDecoder | Creates a new input stream for reading archives created by the  XMLEncoderclass. | 
| XMLDecoder | Creates a new input stream for reading archives created by the  XMLEncoderclass. | 
| XMLDecoder | Creates a new decoder to parse XML archives created by the  XMLEncoderclass. | 
| Modifier and Type | Method | Description | 
|---|---|---|
| void | close() | This method closes the input stream associated with this stream. | 
| static DefaultHandler | createHandler | Creates a new handler for SAX parser that can be used to parse embedded XML archives created by the  XMLEncoderclass. | 
| 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 | setExceptionListener | Sets the exception handler for this stream to  exceptionListener. | 
| void | setOwner | Sets the owner of this decoder to  owner. | 
public XMLDecoder(InputStream in)
XMLEncoder class.in - The underlying stream.public XMLDecoder(InputStream in, Object owner)
XMLEncoder class.in - The underlying stream.owner - The owner of this stream.public XMLDecoder(InputStream in, Object owner, ExceptionListener exceptionListener)
XMLEncoder class.in - the underlying stream.owner - the owner of this stream.exceptionListener - the exception handler for the stream; if null the default exception listener will be used.public XMLDecoder(InputStream in, Object owner, ExceptionListener exceptionListener, ClassLoader cl)
XMLEncoder class.in - the underlying stream. null may be passed without error, though the resulting XMLDecoder will be uselessowner - the owner of this stream. null is a legal valueexceptionListener - the exception handler for the stream, or null to use the defaultcl - the class loader used for instantiating objects. null indicates that the default class loader should be usedpublic XMLDecoder(InputSource is)
XMLEncoder class. If the input source is is null, no exception is thrown and no parsing is performed. This behavior is similar to behavior of other constructors that use InputStream as a parameter.is - the input source to parsepublic void close()
close in interface AutoCloseable
public void setExceptionListener(ExceptionListener exceptionListener)
exceptionListener. The exception handler is notified when this stream catches recoverable exceptions.exceptionListener - The exception handler for this stream; if null the default exception listener will be used.public ExceptionListener getExceptionListener()
public Object readObject()
ArrayIndexOutOfBoundsException - if the stream contains no objects (or no more objects)public void setOwner(Object owner)
owner.owner - The owner of this decoder.public Object getOwner()
public static DefaultHandler createHandler(Object owner, ExceptionListener el, ClassLoader cl)
XMLEncoder class. The owner should be used if parsed XML document contains the method call within context of the <java> element. The null value may cause illegal parsing in such case. The same problem may occur, if the owner class does not contain expected method to call. See details  here.owner - the owner of the default handler that can be used as a value of <java> elementel - the exception handler for the parser, or null to use the default exception handlercl - the class loader used for instantiating objects, or null to use the default class loaderDefaultHandler for SAX parser
    © 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
    https://docs.oracle.com/en/java/javase/21/docs/api/java.desktop/java/beans/XMLDecoder.html