Package org.basex.io.serial
Class Serializer
java.lang.Object
org.basex.io.serial.Serializer
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
BuilderSerializer,OutputSerializer
This is an interface for serializing XQuery values.
- Author:
- BaseX Team 2005-21, BSD License, Christian Gruen
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected QNmCurrent element name.Stack with names of opened elements.protected booleanIndentation flag.protected intCurrent level.protected booleanIndicates if at least one item was already serialized.protected StaticContextStatic context.protected intFlag for skipping elements. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidSerializes an atomic value.protected voidattribute(byte[] name, byte[] value, boolean standalone) Serializes an attribute.voidclose()Closes the serializer.protected voidcloseDoc()Closes a document.protected final voidCloses an element.protected voidcomment(byte[] value) Serializes a comment.protected voidCloses an element.booleanfinished()Tests if the serialization was interrupted.protected voidCloses an empty element.protected voidFinishes an opening element node.protected voidSerializes a function item.static Serializerget(OutputStream os) Returns a default serializer.static Serializerget(OutputStream os, SerializerOptions sopts) Returns a specific serializer.protected voidnamespace(byte[] prefix, byte[] uri, boolean standalone) Serializes a namespace.protected voidSerializes the specified node.protected final byte[]nsUri(byte[] prefix) Returns the namespace URI currently bound by the given prefix.protected voidopenDoc(byte[] name) Opens a document.protected final voidopenElement(QNm name) Opens an element.protected voidpi(byte[] name, byte[] value) Serializes a processing instruction.voidreset()Resets the serializer (indentation, etc).sc(StaticContext sctx) Assigns the static context.voidSerializes the specified item, which may be a node or an atomic value.protected booleanskipElement(ANode node) Checks if an element should be skipped.protected voidStarts an element.protected voidSerializes a text.static byte[]value(byte[] value, int quote, boolean chop) Serializes the specified value.
-
Field Details
-
elems
Stack with names of opened elements. -
level
protected int levelCurrent level. -
elem
Current element name. -
indent
protected boolean indentIndentation flag. -
sc
Static context. -
more
protected boolean moreIndicates if at least one item was already serialized. -
skip
protected int skipFlag for skipping elements.
-
-
Constructor Details
-
Serializer
public Serializer()
-
-
Method Details
-
get
Returns a default serializer.- Parameters:
os- output stream reference- Returns:
- serializer
- Throws:
IOException- I/O exception
-
get
Returns a specific serializer.- Parameters:
os- output stream referencesopts- serialization parameters (may benull)- Returns:
- serializer
- Throws:
IOException- I/O exception
-
serialize
Serializes the specified item, which may be a node or an atomic value.- Parameters:
item- item to be serialized- Throws:
IOException- I/O exception
-
close
Closes the serializer.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- I/O exception
-
finished
public boolean finished()Tests if the serialization was interrupted.- Returns:
- result of check
-
reset
public void reset()Resets the serializer (indentation, etc). -
sc
Assigns the static context.- Parameters:
sctx- static context- Returns:
- self-reference
-
node
Serializes the specified node.- Parameters:
node- node to be serialized- Throws:
IOException- I/O exception
-
openElement
Opens an element.- Parameters:
name- element name- Throws:
IOException- I/O exception
-
closeElement
Closes an element.- Throws:
IOException- I/O exception
-
openDoc
Opens a document.- Parameters:
name- name- Throws:
IOException- I/O exception
-
closeDoc
Closes a document.- Throws:
IOException- I/O exception
-
namespace
Serializes a namespace.- Parameters:
prefix- prefixuri- namespace URIstandalone- standalone flag- Throws:
IOException- I/O exception
-
nsUri
protected final byte[] nsUri(byte[] prefix) Returns the namespace URI currently bound by the given prefix.- Parameters:
prefix- namespace prefix- Returns:
- URI if found,
nullotherwise
-
skipElement
Checks if an element should be skipped.- Parameters:
node- node to be serialized- Returns:
- result of check
-
attribute
Serializes an attribute.- Parameters:
name- namevalue- valuestandalone- standalone flag- Throws:
IOException- I/O exception
-
startOpen
Starts an element.- Parameters:
name- element name- Throws:
IOException- I/O exception
-
finishOpen
Finishes an opening element node.- Throws:
IOException- I/O exception
-
finishEmpty
Closes an empty element.- Throws:
IOException- I/O exception
-
finishClose
Closes an element.- Throws:
IOException- I/O exception
-
text
Serializes a text.- Parameters:
value- valueftp- full-text positions, used for visualization highlighting- Throws:
IOException- I/O exception
-
comment
Serializes a comment.- Parameters:
value- value- Throws:
IOException- I/O exception
-
pi
Serializes a processing instruction.- Parameters:
name- namevalue- value- Throws:
IOException- I/O exception
-
atomic
Serializes an atomic value.- Parameters:
item- item- Throws:
IOException- I/O exception
-
function
Serializes a function item.- Parameters:
item- item- Throws:
IOException- I/O exception
-
value
public static byte[] value(byte[] value, int quote, boolean chop) Serializes the specified value.- Parameters:
value- valuechop- chop large tokensquote- character for quoting the value; ignored ifnull- Returns:
- value
-