public class StatefulWriter extends WriterWrapper
HierarchicalStreamWriter implementations, that keeps the state.
Writing in a wrong state will throw a StreamException, that wraps either an
IOException (writing to a closed writer) or an IllegalStateException. The
implementation will also track unbalanced nodes or multiple attributes with the same name.| Modifier and Type | Field and Description |
|---|---|
static int |
STATE_CLOSED
STATE_CLOSED is the state if the writer has been closed. |
static int |
STATE_NODE_END
STATE_NODE_END is the state if a node has ended |
static int |
STATE_NODE_START
STATE_NODE_START is the state of a new node has been started. |
static int |
STATE_OPEN
STATE_OPEN is the initial value of the writer. |
static int |
STATE_VALUE
STATE_VALUE is the state if the value of a node has been written. |
wrapped| Constructor and Description |
|---|
StatefulWriter(HierarchicalStreamWriter wrapped)
Constructs a StatefulWriter.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAttribute(String name,
String value) |
void |
close()
Close the writer, if necessary.
|
void |
endNode() |
void |
flush()
Flush the writer, if necessary.
|
void |
setValue(String text)
Write the value (text content) of the current node.
|
void |
startNode(String name) |
void |
startNode(String name,
Class clazz) |
int |
state()
Retrieve the state of the writer.
|
underlyingWriterpublic static int STATE_OPEN
STATE_OPEN is the initial value of the writer.public static int STATE_NODE_START
STATE_NODE_START is the state of a new node has been started.public static int STATE_VALUE
STATE_VALUE is the state if the value of a node has been written.public static int STATE_NODE_END
STATE_NODE_END is the state if a node has endedpublic static int STATE_CLOSED
STATE_CLOSED is the state if the writer has been closed.public StatefulWriter(HierarchicalStreamWriter wrapped)
wrapped - the wrapped writerpublic void startNode(String name)
startNode in interface HierarchicalStreamWriterstartNode in class WriterWrapperpublic void startNode(String name, Class clazz)
startNode in interface ExtendedHierarchicalStreamWriterstartNode in class WriterWrapperpublic void addAttribute(String name, String value)
addAttribute in interface HierarchicalStreamWriteraddAttribute in class WriterWrapperpublic void setValue(String text)
HierarchicalStreamWritersetValue in interface HierarchicalStreamWritersetValue in class WriterWrapperpublic void endNode()
endNode in interface HierarchicalStreamWriterendNode in class WriterWrapperpublic void flush()
HierarchicalStreamWriterflush in interface HierarchicalStreamWriterflush in class WriterWrapperpublic void close()
HierarchicalStreamWriterclose in interface HierarchicalStreamWriterclose in class WriterWrapperpublic int state()
STATE_OPEN,
STATE_NODE_START,
STATE_VALUE,
STATE_NODE_END,
STATE_CLOSEDCopyright © 2020 Internet2. All rights reserved.