org.apache.axis2.format
Class TextFromElementReader

java.lang.Object
  extended by java.io.Reader
      extended by org.apache.axis2.format.TextFromElementReader
All Implemented Interfaces:
java.io.Closeable, java.lang.Readable

public class TextFromElementReader
extends java.io.Reader

Reader implementation that extracts the text nodes from an element given by an XMLStreamReader. The expected input is a document with only a document element (as produced by org.apache.axiom.om.OMElement.OMElement#getXMLStreamReader()). The class will extract the text nodes that are direct children of that element, i.e. it uses the same conventions as org.apache.axiom.om.OMElement.OMElement#getText(). It will call XMLStreamReader.close() when the end of the document is reached or when close() is called.

The main purpose of this class is to provide a convenient and efficient way to get the text content of an element without converting it first to a string, i.e. without using org.apache.axiom.om.OMElement.OMElement#getText(). This is important for potentially large contents, for which this class guarantees constant memory usage.

Note that this class should in general not be used directly. Instead, ElementHelper#getTextAsStream(org.apache.axiom.om.OMElement) should be called to get the most efficient stream implementation for a given an element.

NOTICE: The code in this class will be moved to Axiom (or somewhere else). Use with care!


Field Summary
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
TextFromElementReader(javax.xml.stream.XMLStreamReader stream)
          Constructor.
 
Method Summary
 void close()
           
 int read(char[] cbuf, int off, int len)
           
 
Methods inherited from class java.io.Reader
mark, markSupported, read, read, read, ready, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextFromElementReader

public TextFromElementReader(javax.xml.stream.XMLStreamReader stream)
Constructor.

Parameters:
stream - the stream to extract the text nodes from
Throws:
org.apache.axiom.om.OMException - if the stream doesn't start with the expected events
Method Detail

read

public int read(char[] cbuf,
                int off,
                int len)
         throws java.io.IOException
Specified by:
read in class java.io.Reader
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Specified by:
close in class java.io.Reader
Throws:
java.io.IOException


Copyright © 2004-2009 The Apache Software Foundation. All Rights Reserved.