- java.lang.Object
-
- java.beans.XMLDecoder
-
- All Implemented Interfaces:
- AutoCloseable
public class XMLDecoder extends Object implements AutoCloseable
TheXMLDecoder
class is used to read XML documents created using theXMLEncoder
and is used just like theObjectInputStream
. For example, one can use the following fragment to read the first object defined in an XML document written by theXMLEncoder
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.
- Since:
- 1.4
- See Also:
XMLEncoder
,ObjectInputStream
-
-
Constructor Summary
Constructors Constructor and Description XMLDecoder(InputSource is)
Creates a new decoder to parse XML archives created by theXMLEncoder
class.XMLDecoder(InputStream in)
Creates a new input stream for reading archives created by theXMLEncoder
class.XMLDecoder(InputStream in, Object owner)
Creates a new input stream for reading archives created by theXMLEncoder
class.XMLDecoder(InputStream in, Object owner, ExceptionListener exceptionListener)
Creates a new input stream for reading archives created by theXMLEncoder
class.XMLDecoder(InputStream in, Object owner, ExceptionListener exceptionListener, ClassLoader cl)
Creates a new input stream for reading archives created by theXMLEncoder
class.
-
Method Summary
Methods Modifier and Type Method and Description void
close()
This method closes the input stream associated with this stream.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 theXMLEncoder
class.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(ExceptionListener exceptionListener)
Sets the exception handler for this stream toexceptionListener
.void
setOwner(Object owner)
Sets the owner of this decoder toowner
.
-
-
-
Constructor Detail
-
XMLDecoder
public XMLDecoder(InputStream in)
Creates a new input stream for reading archives created by theXMLEncoder
class.- Parameters:
in
- The underlying stream.- See Also:
XMLEncoder.XMLEncoder(java.io.OutputStream)
-
XMLDecoder
public XMLDecoder(InputStream in, Object owner)
Creates a new input stream for reading archives created by theXMLEncoder
class.- Parameters:
in
- The underlying stream.owner
- The owner of this stream.
-
XMLDecoder
public XMLDecoder(InputStream in, Object owner, ExceptionListener exceptionListener)
Creates a new input stream for reading archives created by theXMLEncoder
class.- Parameters:
in
- the underlying stream.owner
- the owner of this stream.exceptionListener
- the exception handler for the stream; ifnull
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 theXMLEncoder
class.- Parameters:
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, ornull
to use the defaultcl
- the class loader used for instantiating objects.null
indicates that the default class loader should be used- Since:
- 1.5
-
XMLDecoder
public XMLDecoder(InputSource is)
Creates a new decoder to parse XML archives created by theXMLEncoder
class. If the input sourceis
isnull
, no exception is thrown and no parsing is performed. This behavior is similar to behavior of other constructors that useInputStream
as a parameter.- Parameters:
is
- the input source to parse- Since:
- 1.7
-
-
Method Detail
-
close
public void close()
This method closes the input stream associated with this stream.- Specified by:
close
in interfaceAutoCloseable
-
setExceptionListener
public void setExceptionListener(ExceptionListener exceptionListener)
Sets the exception handler for this stream toexceptionListener
. The exception handler is notified when this stream catches recoverable exceptions.- Parameters:
exceptionListener
- The exception handler for this stream; ifnull
the default exception listener will be used.- See Also:
getExceptionListener()
-
getExceptionListener
public ExceptionListener getExceptionListener()
Gets the exception handler for this stream.- Returns:
- The exception handler for this stream. Will return the default exception listener if this has not explicitly been set.
- See Also:
setExceptionListener(java.beans.ExceptionListener)
-
readObject
public Object readObject()
Reads the next object from the underlying input stream.- Returns:
- the next object read
- Throws:
ArrayIndexOutOfBoundsException
- if the stream contains no objects (or no more objects)- See Also:
XMLEncoder.writeObject(java.lang.Object)
-
setOwner
public void setOwner(Object owner)
Sets the owner of this decoder toowner
.- Parameters:
owner
- The owner of this decoder.- See Also:
getOwner()
-
getOwner
public Object getOwner()
Gets the owner of this decoder.- Returns:
- The owner of this decoder.
- See Also:
setOwner(java.lang.Object)
-
createHandler
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 theXMLEncoder
class. Theowner
should be used if parsed XML document contains the method call within context of the <java> element. Thenull
value may cause illegal parsing in such case. The same problem may occur, if theowner
class does not contain expected method to call. See details here.- Parameters:
owner
- the owner of the default handler that can be used as a value of <java> elementel
- the exception handler for the parser, ornull
to use the default exception handlercl
- the class loader used for instantiating objects, ornull
to use the default class loader- Returns:
- an instance of
DefaultHandler
for SAX parser - Since:
- 1.7
-
-
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 11/06/2005, zuletzt geändert 04/03/2020
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/java-api-rf-java/beans/XMLDecoder.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.
Referenzen
Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.