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 OMContainer.getXMLStreamReader()).
The class will extract the text nodes that are direct children of that element, i.e. it uses
the same conventions as 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
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,
org.apache.axiom.om.util.ElementHelper#getTextAsStream(org.apache.axiom.om.OMElement)
should be called to get the most efficient stream implementation for a given an element.
| Modifier and Type | Field and Description |
|---|---|
private boolean |
allowNonTextChildren |
private boolean |
endOfStream
Flag indicating that we have reached the end of the document and that the underlying
parser has been closed.
|
private int |
skipDepth
The current depth relative to the document element (not the document).
|
private int |
sourceStart
The current position in the character data of the event, or -1 if all the character data
has been consumed and a new event needs to be requested from the parser.
|
private javax.xml.stream.XMLStreamReader |
stream |
| Constructor and Description |
|---|
TextFromElementReader(javax.xml.stream.XMLStreamReader stream,
boolean allowNonTextChildren) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
int |
read(char[] cbuf,
int off,
int len) |
private final javax.xml.stream.XMLStreamReader stream
private final boolean allowNonTextChildren
private boolean endOfStream
private int skipDepth
private int sourceStart
TextFromElementReader(javax.xml.stream.XMLStreamReader stream,
boolean allowNonTextChildren)
public int read(char[] cbuf,
int off,
int len)
throws java.io.IOException
read in class java.io.Readerjava.io.IOExceptionpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.Readerjava.io.IOException