Class NodeInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class NodeInputStream
    extends java.io.InputStream
    Adapter class to present the content of a DOM Node (e.g. a Document) as an InputStream using a DOM to Stream transformation.
    • Constructor Summary

      Constructors 
      Constructor Description
      NodeInputStream​(org.w3c.dom.Node rootNode)
      Simple constructor
      NodeInputStream​(org.w3c.dom.Node rootNode, java.util.Properties outputProperties)
      Simple constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()
      InputStream method
      void close()
      InputStream method Note that calling close allows a repeated read of the content
      private void ensureContentAvailable()
      Do the actual work of serializing the node to bytes
      int read()
      InputStream method
      private int reallyAvailable()  
      • Methods inherited from class java.io.InputStream

        mark, markSupported, nullInputStream, read, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • rootNode

        private final org.w3c.dom.Node rootNode
      • nodeContentBytes

        private final java.io.ByteArrayOutputStream nodeContentBytes
      • outputProperties

        private final java.util.Properties outputProperties
      • atPos

        private int atPos
    • Constructor Detail

      • NodeInputStream

        public NodeInputStream​(org.w3c.dom.Node rootNode)
        Simple constructor
        Parameters:
        rootNode - the node to be presented as an input stream
      • NodeInputStream

        public NodeInputStream​(org.w3c.dom.Node rootNode,
                               java.util.Properties outputProperties)
        Simple constructor
        Parameters:
        rootNode - the node to be presented as an input stream
    • Method Detail

      • ensureContentAvailable

        private void ensureContentAvailable()
                                     throws java.io.IOException
        Do the actual work of serializing the node to bytes
        Throws:
        java.io.IOException - if serialization goes awry
      • read

        public int read()
                 throws java.io.IOException
        InputStream method
        Specified by:
        read in class java.io.InputStream
        Returns:
        byte as read
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        InputStream method Note that calling close allows a repeated read of the content
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.InputStream
        Throws:
        java.io.IOException
      • available

        public int available()
                      throws java.io.IOException
        InputStream method
        Overrides:
        available in class java.io.InputStream
        Returns:
        number of bytes available
        Throws:
        java.io.IOException
      • reallyAvailable

        private int reallyAvailable()
        Returns:
        really available