Class Emitter

java.lang.Object
org.yaml.snakeyaml.emitter.Emitter
All Implemented Interfaces:
Emitable

public final class Emitter extends 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 Details

    • MIN_INDENT

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

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

      private static final char[] SPACE
    • SPACES_PATTERN

      private static final Pattern SPACES_PATTERN
    • INVALID_ANCHOR

      private static final Set<Character> INVALID_ANCHOR
    • ESCAPE_REPLACEMENTS

      private static final Map<Character,String> ESCAPE_REPLACEMENTS
    • DEFAULT_TAG_PREFIXES

      private static final Map<String,String> DEFAULT_TAG_PREFIXES
    • stream

      private final Writer stream
    • states

      private final ArrayStack<EmitterState> states
    • state

      private EmitterState state
    • events

      private final Queue<Event> events
    • event

      private Event event
    • indents

      private final ArrayStack<Integer> indents
    • indent

      private 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 Boolean canonical
    • prettyFlow

      private final 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 Map<String,String> tagPrefixes
    • preparedAnchor

      private String preparedAnchor
    • preparedTag

      private String preparedTag
    • analysis

      private ScalarAnalysis analysis
    • style

    • blockCommentsCollector

      private final CommentEventsCollector blockCommentsCollector
    • inlineCommentsCollector

      private final CommentEventsCollector inlineCommentsCollector
    • HANDLE_FORMAT

      private static final Pattern HANDLE_FORMAT
  • Constructor Details

    • Emitter

      public Emitter(Writer stream, DumperOptions opts)
      Create
      Parameters:
      stream - - output to write to
      opts - - options
  • Method Details

    • emit

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

      private boolean needMoreEvents()
    • needEvents

      private boolean needEvents(Iterator<Event> iter, int count)
    • increaseIndent

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

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

      private void expectAlias() throws IOException
      Throws:
      IOException
    • expectScalar

      private void expectScalar() throws IOException
      Throws:
      IOException
    • expectFlowSequence

      private void expectFlowSequence() throws IOException
      Throws:
      IOException
    • expectFlowMapping

      private void expectFlowMapping() throws IOException
      Throws:
      IOException
    • expectBlockSequence

      private void expectBlockSequence() throws IOException
      Throws:
      IOException
    • expectBlockMapping

      private void expectBlockMapping() throws IOException
      Throws:
      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(String indicator) throws IOException
      Throws:
      IOException
    • processTag

      private void processTag() throws IOException
      Emit the tag for the current event
      Throws:
      IOException
    • chooseScalarStyle

      private DumperOptions.ScalarStyle chooseScalarStyle()
      Choose the scalar style based on the contents of the scalar and scalar style chosen by Representer
      Returns:
      ScalarStyle to apply for this scala event
    • processScalar

      private void processScalar() throws IOException
      Throws:
      IOException
    • prepareVersion

      private String prepareVersion(DumperOptions.Version version)
    • prepareTagHandle

      private String prepareTagHandle(String handle)
    • prepareTagPrefix

      private String prepareTagPrefix(String prefix)
    • prepareTag

      private String prepareTag(String tag)
      Detect whether the tag starts with a standard handle and add ! when it does not
      Parameters:
      tag - - raw (complete tag)
      Returns:
      formatted tag ready to emit
    • prepareAnchor

      static String prepareAnchor(String anchor)
    • hasLeadingZero

      private static boolean hasLeadingZero(String scalar)
    • analyzeScalar

      private ScalarAnalysis analyzeScalar(String scalar)
    • flushStream

      void flushStream() throws IOException
      Throws:
      IOException
    • writeStreamStart

      void writeStreamStart()
    • writeStreamEnd

      void writeStreamEnd() throws IOException
      Throws:
      IOException
    • writeIndicator

      void writeIndicator(String indicator, boolean needWhitespace, boolean whitespace, boolean indentation) throws IOException
      Throws:
      IOException
    • writeIndent

      void writeIndent() throws IOException
      Throws:
      IOException
    • writeWhitespace

      private void writeWhitespace(int length) throws IOException
      Throws:
      IOException
    • writeLineBreak

      private void writeLineBreak(String data) throws IOException
      Throws:
      IOException
    • writeVersionDirective

      void writeVersionDirective(String versionText) throws IOException
      Throws:
      IOException
    • writeTagDirective

      void writeTagDirective(String handleText, String prefixText) throws IOException
      Throws:
      IOException
    • writeSingleQuoted

      private void writeSingleQuoted(String text, boolean split) throws IOException
      Throws:
      IOException
    • writeDoubleQuoted

      private void writeDoubleQuoted(String text, boolean split) throws IOException
      Throws:
      IOException
    • writeCommentLines

      private boolean writeCommentLines(List<CommentLine> commentLines) throws IOException
      Throws:
      IOException
    • writeBlockComment

      private void writeBlockComment() throws IOException
      Throws:
      IOException
    • writeInlineComments

      private boolean writeInlineComments() throws IOException
      Throws:
      IOException
    • determineBlockHints

      private String determineBlockHints(String text)
    • writeFolded

      void writeFolded(String text, boolean split) throws IOException
      Throws:
      IOException
    • writeLiteral

      void writeLiteral(String text) throws IOException
      Throws:
      IOException
    • writePlain

      void writePlain(String text, boolean split) throws IOException
      Throws:
      IOException