Class StreamReader


  • public final class StreamReader
    extends java.lang.Object
    Read the provided stream of code points into String and implement look-ahead operations. Checks if code points are in the allowed range.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private char[] buffer  
      private int bufferSize  
      private int[] codePointsWindow
      Read data (as a moving window for input stream)
      private int column  
      private int dataLength
      Real length of the data in dataWindow
      private int documentIndex  
      private boolean eof  
      private int index
      index is only required to implement 1024 key length restriction and the total length restriction
      private int line  
      private java.lang.String name  
      private int pointer
      The variable points to the current position in the data array
      private java.io.Reader stream  
      private boolean useMarks  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private boolean ensureEnoughData()  
      private boolean ensureEnoughData​(int size)  
      void forward()
      read the next character and move the pointer.
      void forward​(int length)
      read the next length characters and move the pointer.
      int getColumn()  
      int getDocumentIndex()
      Get the position of the currect char in the current YAML document
      int getIndex()  
      int getLine()  
      java.util.Optional<Mark> getMark()
      Generate Mark if it is configured
      static boolean isPrintable​(int c)
      Check if the code point is human-readable
      static boolean isPrintable​(java.lang.String data)
      Check if the all the data is human-readable (used in Representer)
      private void moveIndices​(int length)  
      int peek()
      Peek the next code point (look without moving the pointer)
      int peek​(int index)
      Peek the next index-th code point
      java.lang.String prefix​(int length)
      Create String from code points
      java.lang.String prefixForward​(int length)
      prefix(length) immediately followed by forward(length)
      void resetDocumentIndex()
      Reset the position to start (at the start of a new document in the stream)
      private void update()  
      • Methods inherited from class java.lang.Object

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

      • name

        private final java.lang.String name
      • stream

        private final java.io.Reader stream
      • bufferSize

        private final int bufferSize
      • buffer

        private final char[] buffer
      • useMarks

        private final boolean useMarks
      • codePointsWindow

        private int[] codePointsWindow
        Read data (as a moving window for input stream)
      • dataLength

        private int dataLength
        Real length of the data in dataWindow
      • pointer

        private int pointer
        The variable points to the current position in the data array
      • eof

        private boolean eof
      • index

        private int index
        index is only required to implement 1024 key length restriction and the total length restriction
      • documentIndex

        private int documentIndex
      • line

        private int line
      • column

        private int column
    • Constructor Detail

      • StreamReader

        @Deprecated
        public StreamReader​(java.io.Reader reader,
                            LoadSettings loadSettings)
        Deprecated.
        use the other constructor with LoadSettings first
        Parameters:
        loadSettings - - configuration options
        reader - - the input
      • StreamReader

        public StreamReader​(LoadSettings loadSettings,
                            java.io.Reader reader)
        Create
        Parameters:
        loadSettings - - configuration options
        reader - - the input
      • StreamReader

        @Deprecated
        public StreamReader​(java.lang.String stream,
                            LoadSettings loadSettings)
        Deprecated.
        use the other constructor with LoadSettings first
        Parameters:
        stream - - the input
        loadSettings - - configuration options
      • StreamReader

        public StreamReader​(LoadSettings loadSettings,
                            java.lang.String stream)
        Create
        Parameters:
        loadSettings - - configuration options
        stream - - the input
    • Method Detail

      • isPrintable

        public static boolean isPrintable​(java.lang.String data)
        Check if the all the data is human-readable (used in Representer)
        Parameters:
        data - - content to be checked for human-readability
        Returns:
        true only when everything is human-readable
      • isPrintable

        public static boolean isPrintable​(int c)
        Check if the code point is human-readable
        Parameters:
        c - - code point to be checked for human-readability
        Returns:
        true only when the code point is human-readable
      • getMark

        public java.util.Optional<Mark> getMark()
        Generate Mark if it is configured
        Returns:
        Mark of the current position or empty Optional otherwise
      • forward

        public void forward()
        read the next character and move the pointer. if the last character is high surrogate one more character will be read
      • forward

        public void forward​(int length)
        read the next length characters and move the pointer. if the last character is high surrogate one more character will be read
        Parameters:
        length - amount of characters to move forward
      • peek

        public int peek()
        Peek the next code point (look without moving the pointer)
        Returns:
        the next code point or 0 if empty
      • peek

        public int peek​(int index)
        Peek the next index-th code point
        Parameters:
        index - to peek
        Returns:
        the next index-th code point or 0 if empty
      • prefix

        public java.lang.String prefix​(int length)
        Create String from code points
        Parameters:
        length - amount of the characters to convert
        Returns:
        the String representation
      • prefixForward

        public java.lang.String prefixForward​(int length)
        prefix(length) immediately followed by forward(length)
        Parameters:
        length - amount of characters to get
        Returns:
        the next length code points
      • ensureEnoughData

        private boolean ensureEnoughData()
      • ensureEnoughData

        private boolean ensureEnoughData​(int size)
      • update

        private void update()
      • getColumn

        public int getColumn()
        Returns:
        current position as number (in characters) from the beginning of the current line
      • moveIndices

        private void moveIndices​(int length)
      • getDocumentIndex

        public int getDocumentIndex()
        Get the position of the currect char in the current YAML document
        Returns:
        index of the current position from the beginning of the current document
      • resetDocumentIndex

        public void resetDocumentIndex()
        Reset the position to start (at the start of a new document in the stream)
      • getIndex

        public int getIndex()
        Returns:
        current position as number (in characters) from the beginning of the stream
      • getLine

        public int getLine()
        Returns:
        current line from the beginning of the stream