J avolution v3.7 (J2SE 1.5+)

javolution.xml
Class XmlInputStream<T>

java.lang.Object
  extended by java.io.InputStream
      extended by javolution.xml.XmlInputStream<T>
All Implemented Interfaces:
java.io.Closeable, Reusable

public class XmlInputStream<T>
extends java.io.InputStream
implements Reusable

This class represents an object input stream using ObjectReader for object deserialization.

Instances of this class embed their own data buffer, wrapping using a java.io.BufferedInputStream is therefore unnescessary.

Version:
2.2, January 8, 2005
Author:
Jean-Marie Dautelle
See Also:
XmlOutputStream

Constructor Summary
XmlInputStream()
          Default constructor.
XmlInputStream(ObjectReader<T> reader)
          Creates a xml input stream using the specified object reader.
 
Method Summary
 void close()
          Closes and resets this stream for reuse.
 int read()
          Reads the next byte of data from the input stream.
 int read(byte[] b, int off, int len)
          Reads up to len bytes of data from the input stream into an array of bytes.
 T readObject()
          Reads an object from the underlying stream using an ObjectReader.
 void reset()
          Resets the internal state of this object to its default values.
 XmlInputStream setInputStream(java.io.InputStream in)
          Sets the underlying input source for this stream.
 
Methods inherited from class java.io.InputStream
available, mark, markSupported, read, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlInputStream

public XmlInputStream()
Default constructor.


XmlInputStream

public XmlInputStream(ObjectReader<T> reader)
Creates a xml input stream using the specified object reader.

Parameters:
reader - the object reader.
Method Detail

setInputStream

public XmlInputStream setInputStream(java.io.InputStream in)
Sets the underlying input source for this stream.

Parameters:
in - the input source.
Returns:
this
Throws:
java.lang.IllegalStateException - if this stream is being reused and it has not been closed or reset.

readObject

public T readObject()
             throws java.io.IOException
Reads an object from the underlying stream using an ObjectReader.

Returns:
the object read from its xml representation.
Throws:
java.io.IOException - if an I/O error occurs.

close

public void close()
           throws java.io.IOException
Closes and resets this stream for reuse.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.InputStream
Throws:
java.io.IOException - if an I/O error occurs.

read

public int read()
         throws java.io.IOException
Reads the next byte of data from the input stream.

Specified by:
read in class java.io.InputStream
Returns:
the next byte of data, or -1 if the end of the stream is reached.
Throws:
java.io.IOException - if an I/O error occurs.

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Reads up to len bytes of data from the input stream into an array of bytes.

Overrides:
read in class java.io.InputStream
Parameters:
b - the buffer into which the data is read.
off - the start offset in array b at which the data is written.
len - the maximum number of bytes to read.
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
Throws:
java.io.IOException - if an I/O error occurs.

reset

public void reset()
Description copied from interface: Reusable
Resets the internal state of this object to its default values.

Specified by:
reset in interface Reusable
Overrides:
reset in class java.io.InputStream

J avolution v3.7 (J2SE 1.5+)

Copyright © 2006 Javolution.