org.backsource.utils.io
Class DOMInputStream

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.PipedInputStream
          extended byorg.backsource.utils.io.DOMInputStream

public class DOMInputStream
extends java.io.PipedInputStream

A stream that reads from a DOM Document (much like a FileInputStream reads from a file).

With DOMInputStream it is possible to setup an InputStream that reads directly from a DOM Document without having to write it out to an OutputStream first. This is however done with the use of two threads; so this class should probably not be used in EJB:s.

Since the DOM tree is serializised it is important to notice that the same behaviour as when doing a default transformations i valid: i.e one has to set encoding and stuff like this if the default behaviour is not good enough.It is possible to use the generic setPropertyMethod to do this; or some of the convinience methods. Use the OutputKeys properties. All tese properties must be set before any reads are done from the stream.

To solve resolve problems it is possible to use the ResolverContext to set a se.tim.utils.xml.Resolver that should be used during serialization.

Here are some example of properties to set:

    // Make output indented
    is.setProperty(OutputKeys.INDENT, "yes");

    // Set another encoding that UTF-8
    is.setProperty(OutputKeys.ENCODING, "iso-8859-1");

    // Don't include XML prolog
    is.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
 

Version:
$Revision: 1.1.1.1 $
Author:
Peter Antman

Field Summary
 
Fields inherited from class java.io.PipedInputStream
buffer, in, out, PIPE_SIZE
 
Constructor Summary
DOMInputStream(org.w3c.dom.Document doc)
           
 
Method Summary
 void close()
          Close the serializer and this stream.
 org.w3c.dom.Document getDocument()
          Get the Document this stream reads from.
 java.lang.String getProperty(java.lang.String name)
          Check if a specific property is set.
 int read()
          Start the serializing thread if first read and delegates to parent;reports any exceptions also from the serializer thread
 int read(byte[] b, int off, int len)
          Read, and report any exceptions also from the serializer thread; delegates to parent.
 void setProperty(java.lang.String name, java.lang.String value)
          Set a transformation/serialization property, see OutputKeys for possible types and values.
protected  void startDOMWriter()
          Start the DOM serializer thread.
 
Methods inherited from class java.io.PipedInputStream
available, connect, receive
 
Methods inherited from class java.io.InputStream
mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DOMInputStream

public DOMInputStream(org.w3c.dom.Document doc)
Method Detail

read

public int read()
         throws java.io.IOException
Start the serializing thread if first read and delegates to parent;reports any exceptions also from the serializer thread

Throws:
java.io.IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Read, and report any exceptions also from the serializer thread; delegates to parent.

Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Close the serializer and this stream.

Throws:
java.io.IOException

setProperty

public void setProperty(java.lang.String name,
                        java.lang.String value)
Set a transformation/serialization property, see OutputKeys for possible types and values.


getProperty

public java.lang.String getProperty(java.lang.String name)
Check if a specific property is set.


startDOMWriter

protected void startDOMWriter()
                       throws java.io.IOException
Start the DOM serializer thread. Any exceptions throw during serializing is saved and reported i the read methods.

Throws:
java.io.IOException

getDocument

public org.w3c.dom.Document getDocument()
Get the Document this stream reads from.



Copyright © 2000-2004 Backsource. All Rights Reserved.