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.
|
underlyingWriter
public 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 HierarchicalStreamWriter
startNode
in class WriterWrapper
public void startNode(String name, Class clazz)
startNode
in interface ExtendedHierarchicalStreamWriter
startNode
in class WriterWrapper
public void addAttribute(String name, String value)
addAttribute
in interface HierarchicalStreamWriter
addAttribute
in class WriterWrapper
public void setValue(String text)
HierarchicalStreamWriter
setValue
in interface HierarchicalStreamWriter
setValue
in class WriterWrapper
public void endNode()
endNode
in interface HierarchicalStreamWriter
endNode
in class WriterWrapper
public void flush()
HierarchicalStreamWriter
flush
in interface HierarchicalStreamWriter
flush
in class WriterWrapper
public void close()
HierarchicalStreamWriter
close
in interface HierarchicalStreamWriter
close
in class WriterWrapper
public int state()
STATE_OPEN
,
STATE_NODE_START
,
STATE_VALUE
,
STATE_NODE_END
,
STATE_CLOSED
Copyright © 2004–2017 XStream. All rights reserved.