Class Serializer

java.lang.Object
org.basex.io.serial.Serializer
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
BuilderSerializer, OutputSerializer

public abstract class Serializer extends Object implements Closeable
This is an interface for serializing XQuery values.
Author:
BaseX Team 2005-21, BSD License, Christian Gruen
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected QNm
    Current element name.
    protected final Stack<QNm>
    Stack with names of opened elements.
    protected boolean
    Indentation flag.
    protected int
    Current level.
    protected boolean
    Indicates if at least one item was already serialized.
    protected StaticContext
    Static context.
    protected int
    Flag for skipping elements.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    atomic(Item item)
    Serializes an atomic value.
    protected void
    attribute(byte[] name, byte[] value, boolean standalone)
    Serializes an attribute.
    void
    Closes the serializer.
    protected void
    Closes a document.
    protected final void
    Closes an element.
    protected void
    comment(byte[] value)
    Serializes a comment.
    protected void
    Closes an element.
    boolean
    Tests if the serialization was interrupted.
    protected void
    Closes an empty element.
    protected void
    Finishes an opening element node.
    protected void
    Serializes a function item.
    static Serializer
    Returns a default serializer.
    static Serializer
    Returns a specific serializer.
    protected void
    namespace(byte[] prefix, byte[] uri, boolean standalone)
    Serializes a namespace.
    protected void
    node(ANode node)
    Serializes the specified node.
    protected final byte[]
    nsUri(byte[] prefix)
    Returns the namespace URI currently bound by the given prefix.
    protected void
    openDoc(byte[] name)
    Opens a document.
    protected final void
    Opens an element.
    protected void
    pi(byte[] name, byte[] value)
    Serializes a processing instruction.
    void
    Resets the serializer (indentation, etc).
    Assigns the static context.
    void
    Serializes the specified item, which may be a node or an atomic value.
    protected boolean
    Checks if an element should be skipped.
    protected void
    startOpen(QNm name)
    Starts an element.
    protected void
    text(byte[] value, FTPos ftp)
    Serializes a text.
    static byte[]
    value(byte[] value, int quote, boolean chop)
    Serializes the specified value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • elems

      protected final Stack<QNm> elems
      Stack with names of opened elements.
    • level

      protected int level
      Current level.
    • elem

      protected QNm elem
      Current element name.
    • indent

      protected boolean indent
      Indentation flag.
    • sc

      protected StaticContext sc
      Static context.
    • more

      protected boolean more
      Indicates if at least one item was already serialized.
    • skip

      protected int skip
      Flag for skipping elements.
  • Constructor Details

    • Serializer

      public Serializer()
  • Method Details

    • get

      public static Serializer get(OutputStream os) throws IOException
      Returns a default serializer.
      Parameters:
      os - output stream reference
      Returns:
      serializer
      Throws:
      IOException - I/O exception
    • get

      public static Serializer get(OutputStream os, SerializerOptions sopts) throws IOException
      Returns a specific serializer.
      Parameters:
      os - output stream reference
      sopts - serialization parameters (may be null)
      Returns:
      serializer
      Throws:
      IOException - I/O exception
    • serialize

      public void serialize(Item item) throws IOException
      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

      public void close() throws IOException
      Closes the serializer.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      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

      public Serializer sc(StaticContext sctx)
      Assigns the static context.
      Parameters:
      sctx - static context
      Returns:
      self-reference
    • node

      protected void node(ANode node) throws IOException
      Serializes the specified node.
      Parameters:
      node - node to be serialized
      Throws:
      IOException - I/O exception
    • openElement

      protected final void openElement(QNm name) throws IOException
      Opens an element.
      Parameters:
      name - element name
      Throws:
      IOException - I/O exception
    • closeElement

      protected final void closeElement() throws IOException
      Closes an element.
      Throws:
      IOException - I/O exception
    • openDoc

      protected void openDoc(byte[] name) throws IOException
      Opens a document.
      Parameters:
      name - name
      Throws:
      IOException - I/O exception
    • closeDoc

      protected void closeDoc() throws IOException
      Closes a document.
      Throws:
      IOException - I/O exception
    • namespace

      protected void namespace(byte[] prefix, byte[] uri, boolean standalone) throws IOException
      Serializes a namespace.
      Parameters:
      prefix - prefix
      uri - namespace URI
      standalone - 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, null otherwise
    • skipElement

      protected boolean skipElement(ANode node)
      Checks if an element should be skipped.
      Parameters:
      node - node to be serialized
      Returns:
      result of check
    • attribute

      protected void attribute(byte[] name, byte[] value, boolean standalone) throws IOException
      Serializes an attribute.
      Parameters:
      name - name
      value - value
      standalone - standalone flag
      Throws:
      IOException - I/O exception
    • startOpen

      protected void startOpen(QNm name) throws IOException
      Starts an element.
      Parameters:
      name - element name
      Throws:
      IOException - I/O exception
    • finishOpen

      protected void finishOpen() throws IOException
      Finishes an opening element node.
      Throws:
      IOException - I/O exception
    • finishEmpty

      protected void finishEmpty() throws IOException
      Closes an empty element.
      Throws:
      IOException - I/O exception
    • finishClose

      protected void finishClose() throws IOException
      Closes an element.
      Throws:
      IOException - I/O exception
    • text

      protected void text(byte[] value, FTPos ftp) throws IOException
      Serializes a text.
      Parameters:
      value - value
      ftp - full-text positions, used for visualization highlighting
      Throws:
      IOException - I/O exception
    • comment

      protected void comment(byte[] value) throws IOException
      Serializes a comment.
      Parameters:
      value - value
      Throws:
      IOException - I/O exception
    • pi

      protected void pi(byte[] name, byte[] value) throws IOException
      Serializes a processing instruction.
      Parameters:
      name - name
      value - value
      Throws:
      IOException - I/O exception
    • atomic

      protected void atomic(Item item) throws IOException
      Serializes an atomic value.
      Parameters:
      item - item
      Throws:
      IOException - I/O exception
    • function

      protected void function(FItem item) throws IOException
      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 - value
      chop - chop large tokens
      quote - character for quoting the value; ignored if null
      Returns:
      value