Class Emitter

  • All Implemented Interfaces:
    Emitable

    public final class Emitter
    extends java.lang.Object
    implements Emitable
     Emitter expects events obeying the following grammar:
     stream ::= STREAM-START document* STREAM-END
     document ::= DOCUMENT-START node DOCUMENT-END
     node ::= SCALAR | sequence | mapping
     sequence ::= SEQUENCE-START node* SEQUENCE-END
     mapping ::= MAPPING-START (node node)* MAPPING-END
     
    • Field Detail

      • MIN_INDENT

        public static final int MIN_INDENT
        indent cannot be zero spaces
        See Also:
        Constant Field Values
      • MAX_INDENT

        public static final int MAX_INDENT
        indent should not be more than 10 spaces
        See Also:
        Constant Field Values
      • SPACE

        private static final char[] SPACE
      • SPACES_PATTERN

        private static final java.util.regex.Pattern SPACES_PATTERN
      • INVALID_ANCHOR

        private static final java.util.Set<java.lang.Character> INVALID_ANCHOR
      • ESCAPE_REPLACEMENTS

        private static final java.util.Map<java.lang.Character,​java.lang.String> ESCAPE_REPLACEMENTS
      • DEFAULT_TAG_PREFIXES

        private static final java.util.Map<java.lang.String,​java.lang.String> DEFAULT_TAG_PREFIXES
      • stream

        private final java.io.Writer stream
      • events

        private final java.util.Queue<Event> events
      • event

        private Event event
      • indents

        private final ArrayStack<java.lang.Integer> indents
      • indent

        private java.lang.Integer indent
      • flowLevel

        private int flowLevel
      • rootContext

        private boolean rootContext
      • mappingContext

        private boolean mappingContext
      • simpleKeyContext

        private boolean simpleKeyContext
      • column

        private int column
      • whitespace

        private boolean whitespace
      • indention

        private boolean indention
      • openEnded

        private boolean openEnded
      • canonical

        private final java.lang.Boolean canonical
      • prettyFlow

        private final java.lang.Boolean prettyFlow
      • allowUnicode

        private final boolean allowUnicode
      • bestIndent

        private int bestIndent
      • indicatorIndent

        private final int indicatorIndent
      • indentWithIndicator

        private final boolean indentWithIndicator
      • bestWidth

        private int bestWidth
      • bestLineBreak

        private final char[] bestLineBreak
      • splitLines

        private final boolean splitLines
      • maxSimpleKeyLength

        private final int maxSimpleKeyLength
      • emitComments

        private final boolean emitComments
      • tagPrefixes

        private java.util.Map<java.lang.String,​java.lang.String> tagPrefixes
      • preparedAnchor

        private java.lang.String preparedAnchor
      • preparedTag

        private java.lang.String preparedTag
      • HANDLE_FORMAT

        private static final java.util.regex.Pattern HANDLE_FORMAT
    • Constructor Detail

      • Emitter

        public Emitter​(java.io.Writer stream,
                       DumperOptions opts)
        Create
        Parameters:
        stream - - output to write to
        opts - - options
    • Method Detail

      • emit

        public void emit​(Event event)
                  throws java.io.IOException
        Description copied from interface: Emitable
        Serialise event to bytes
        Specified by:
        emit in interface Emitable
        Parameters:
        event - - the source
        Throws:
        java.io.IOException - if bytes bite
      • needMoreEvents

        private boolean needMoreEvents()
      • needEvents

        private boolean needEvents​(java.util.Iterator<Event> iter,
                                   int count)
      • increaseIndent

        private void increaseIndent​(boolean flow,
                                    boolean indentless)
      • expectNode

        private void expectNode​(boolean root,
                                boolean mapping,
                                boolean simpleKey)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • expectAlias

        private void expectAlias()
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • expectScalar

        private void expectScalar()
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • expectFlowSequence

        private void expectFlowSequence()
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • expectFlowMapping

        private void expectFlowMapping()
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • expectBlockSequence

        private void expectBlockSequence()
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • expectBlockMapping

        private void expectBlockMapping()
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • isFoldedOrLiteral

        private boolean isFoldedOrLiteral​(Event event)
      • checkEmptySequence

        private boolean checkEmptySequence()
      • checkEmptyMapping

        private boolean checkEmptyMapping()
      • checkEmptyDocument

        private boolean checkEmptyDocument()
      • checkSimpleKey

        private boolean checkSimpleKey()
      • processAnchor

        private void processAnchor​(java.lang.String indicator)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • processTag

        private void processTag()
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • processScalar

        private void processScalar()
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • prepareTagHandle

        private java.lang.String prepareTagHandle​(java.lang.String handle)
      • prepareTagPrefix

        private java.lang.String prepareTagPrefix​(java.lang.String prefix)
      • prepareTag

        private java.lang.String prepareTag​(java.lang.String tag)
      • prepareAnchor

        static java.lang.String prepareAnchor​(java.lang.String anchor)
      • hasLeadingZero

        private static boolean hasLeadingZero​(java.lang.String scalar)
      • analyzeScalar

        private ScalarAnalysis analyzeScalar​(java.lang.String scalar)
      • flushStream

        void flushStream()
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • writeStreamStart

        void writeStreamStart()
      • writeStreamEnd

        void writeStreamEnd()
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • writeIndicator

        void writeIndicator​(java.lang.String indicator,
                            boolean needWhitespace,
                            boolean whitespace,
                            boolean indentation)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • writeIndent

        void writeIndent()
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • writeWhitespace

        private void writeWhitespace​(int length)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • writeLineBreak

        private void writeLineBreak​(java.lang.String data)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • writeVersionDirective

        void writeVersionDirective​(java.lang.String versionText)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • writeTagDirective

        void writeTagDirective​(java.lang.String handleText,
                               java.lang.String prefixText)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • writeSingleQuoted

        private void writeSingleQuoted​(java.lang.String text,
                                       boolean split)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • writeDoubleQuoted

        private void writeDoubleQuoted​(java.lang.String text,
                                       boolean split)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • writeCommentLines

        private boolean writeCommentLines​(java.util.List<CommentLine> commentLines)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • writeBlockComment

        private void writeBlockComment()
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • writeInlineComments

        private boolean writeInlineComments()
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • determineBlockHints

        private java.lang.String determineBlockHints​(java.lang.String text)
      • writeFolded

        void writeFolded​(java.lang.String text,
                         boolean split)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • writeLiteral

        void writeLiteral​(java.lang.String text)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • writePlain

        void writePlain​(java.lang.String text,
                        boolean split)
                 throws java.io.IOException
        Throws:
        java.io.IOException