Package com.thoughtworks.xstream.io
Class StatefulWriter
java.lang.Object
com.thoughtworks.xstream.io.WriterWrapper
com.thoughtworks.xstream.io.StatefulWriter
- All Implemented Interfaces:
ExtendedHierarchicalStreamWriter
,HierarchicalStreamWriter
An wrapper for all
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.- Since:
- 1.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate FastStack
private int
private int
static int
STATE_CLOSED
is the state if the writer has been closed.static int
STATE_NODE_END
is the state if a node has endedstatic int
STATE_NODE_START
is the state of a new node has been started.static int
STATE_OPEN
is the initial value of the writer.static int
STATE_VALUE
is the state if the value of a node has been written.Fields inherited from class com.thoughtworks.xstream.io.WriterWrapper
wrapped
-
Constructor Summary
ConstructorsConstructorDescriptionStatefulWriter
(HierarchicalStreamWriter wrapped) Constructs a StatefulWriter. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAttribute
(String name, String value) private void
void
close()
Close the writer, if necessary.void
endNode()
void
flush()
Flush the writer, if necessary.private Object
void
Write the value (text content) of the current node.void
void
private void
int
state()
Retrieve the state of the writer.Methods inherited from class com.thoughtworks.xstream.io.WriterWrapper
underlyingWriter
-
Field Details
-
STATE_OPEN
public static int STATE_OPENSTATE_OPEN
is the initial value of the writer.- Since:
- 1.2
-
STATE_NODE_START
public static int STATE_NODE_STARTSTATE_NODE_START
is the state of a new node has been started.- Since:
- 1.2
-
STATE_VALUE
public static int STATE_VALUESTATE_VALUE
is the state if the value of a node has been written.- Since:
- 1.2
-
STATE_NODE_END
public static int STATE_NODE_ENDSTATE_NODE_END
is the state if a node has ended- Since:
- 1.2
-
STATE_CLOSED
public static int STATE_CLOSEDSTATE_CLOSED
is the state if the writer has been closed.- Since:
- 1.2
-
state
private transient int state -
balance
private transient int balance -
attributes
-
-
Constructor Details
-
StatefulWriter
Constructs a StatefulWriter.- Parameters:
wrapped
- the wrapped writer- Since:
- 1.2
-
-
Method Details
-
startNode
- Specified by:
startNode
in interfaceHierarchicalStreamWriter
- Overrides:
startNode
in classWriterWrapper
-
startNode
- Specified by:
startNode
in interfaceExtendedHierarchicalStreamWriter
- Overrides:
startNode
in classWriterWrapper
-
startNodeCommon
private void startNodeCommon() -
addAttribute
- Specified by:
addAttribute
in interfaceHierarchicalStreamWriter
- Overrides:
addAttribute
in classWriterWrapper
-
setValue
Description copied from interface:HierarchicalStreamWriter
Write the value (text content) of the current node.- Specified by:
setValue
in interfaceHierarchicalStreamWriter
- Overrides:
setValue
in classWriterWrapper
-
endNode
public void endNode()- Specified by:
endNode
in interfaceHierarchicalStreamWriter
- Overrides:
endNode
in classWriterWrapper
-
flush
public void flush()Description copied from interface:HierarchicalStreamWriter
Flush the writer, if necessary.- Specified by:
flush
in interfaceHierarchicalStreamWriter
- Overrides:
flush
in classWriterWrapper
-
close
public void close()Description copied from interface:HierarchicalStreamWriter
Close the writer, if necessary.- Specified by:
close
in interfaceHierarchicalStreamWriter
- Overrides:
close
in classWriterWrapper
-
checkClosed
private void checkClosed() -
state
public int state()Retrieve the state of the writer.- Returns:
- one of the states
- Since:
- 1.2
- See Also:
-
readResolve
-