XMLDecoder (Java Platform SE 6) (original) (raw)
java.beans
Class XMLDecoder
java.lang.Object
java.beans.XMLDecoder
public 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 outLong Term Persistence of JavaBeans Components: XML Schema, an article in The Swing Connection.
Since:
1.4
See Also:
Constructor Summary |
---|
XMLDecoder(InputStream in) Creates a new input stream for reading archives created by the XMLEncoder class. |
[XMLDecoder](../../java/beans/XMLDecoder.html#XMLDecoder%28java.io.InputStream, java.lang.Object%29)(InputStream in,Object owner) Creates a new input stream for reading archives created by the XMLEncoder class. |
[XMLDecoder](../../java/beans/XMLDecoder.html#XMLDecoder%28java.io.InputStream, java.lang.Object, java.beans.ExceptionListener%29)(InputStream in,Object owner,ExceptionListener exceptionListener) Creates a new input stream for reading archives created by the XMLEncoder class. |
[XMLDecoder](../../java/beans/XMLDecoder.html#XMLDecoder%28java.io.InputStream, java.lang.Object, java.beans.ExceptionListener, java.lang.ClassLoader%29)(InputStream in,Object owner,ExceptionListener exceptionListener,ClassLoader cl) 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. |
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 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](../../java/lang/Object.html#wait%28long, int%29) |
Constructor Detail |
---|
XMLDecoder
public XMLDecoder(InputStream in)
Creates a new input stream for reading archives created by the XMLEncoder
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 the XMLEncoder
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 the XMLEncoder
class.
Parameters:
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.
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. null
may be passed without error, though the resulting XMLDecoder will be useless
owner
- the owner of this stream. null
is a legal value
exceptionListener
- the exception handler for the stream, ornull
to use the default
cl
- the class loader used for instantiating objects. null
indicates that the default class loader should be used
Since:
1.5
Method Detail |
---|
close
public void close()
This method closes the input stream associated with this stream.
setExceptionListener
public void setExceptionListener(ExceptionListener exceptionListener)
Sets the exception handler for this stream to exceptionListener
. The exception handler is notified when this stream catches recoverable exceptions.
Parameters:
exceptionListener
- The exception handler for this stream; if null
the default exception listener will be used.
See Also:
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](../../java/lang/ArrayIndexOutOfBoundsException.html "class in java.lang")
- 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 to owner
.
Parameters:
owner
- The owner of this decoder.
See Also:
getOwner
public Object getOwner()
Gets the owner of this decoder.
Returns:
The owner of this decoder.
See Also:
Submit a bug or feature
For further API reference and developer documentation, see Java SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2015, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
Scripting on this page tracks web page traffic, but does not change the content in any way.