Class CssReader


  • final class CssReader
    extends java.lang.Object
    A wrapper around java.io.Reader with a pushback buffer, offset and line+column tracking. This is used by CssScanner.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) class  CssReader.Mark  
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int[] buf  
      (package private) int col
      The current column in the resource being read
      (package private) int curChar
      The char that this reader is currently positioned at, or -1 if EOF is reached.
      (package private) static int DEFAULT_PUSHBACK_BUFFER_SIZE  
      private java.io.Reader in  
      (package private) int line
      The current line in the resource being read
      (package private) int offset
      The offset (in characters) of prevChar from the start of the resource being read.
      private int pos  
      (package private) int prevChar
      The previous char, or 0 if curChar is the first character in the resource being read.
      private int prevLine  
      (package private) java.lang.String systemID
      The systemID of the resource being read.
    • Constructor Summary

      Constructors 
      Constructor Description
      CssReader​(java.io.Reader reader, java.lang.String systemID, int pushbackSize)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) int at​(int n)
      Peek and return the character at position n from current position, or -1 if EOF is reached before or at that position.
      (package private) int[] collect​(int n)
      Reads forward and returns the the next n characters in the stream.
      (package private) CssReader forward​(int n)
      Read forward n characters, or until the next character is EOF.
      (package private) CssReader forward​(com.google.common.base.CharMatcher matcher)
      Read forward until the next non-escaped character matches the given CharMatcher or is EOF.
      (package private) CssReader.Mark mark()  
      (package private) int next()
      Returns the next character in the stream and advances the readers position.
      (package private) int peek()
      Returns the next character in the stream without advancing the readers position.
      (package private) int[] peek​(int n)
      Returns the the next n characters in the stream without advancing the readers position.
      private CssReader reset​(CssReader.Mark mark)  
      java.lang.String toString()  
      (package private) void unread​(int[] cbuf, int off, int len, CssReader.Mark mark)  
      (package private) void unread​(int[] cbuf, CssReader.Mark mark)  
      (package private) void unread​(int ch, CssReader.Mark mark)  
      (package private) void unread​(java.util.List<java.lang.Integer> cbuf, CssReader.Mark mark)  
      • Methods inherited from class java.lang.Object

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

      • DEFAULT_PUSHBACK_BUFFER_SIZE

        static final int DEFAULT_PUSHBACK_BUFFER_SIZE
        See Also:
        Constant Field Values
      • buf

        private final int[] buf
      • pos

        private int pos
      • in

        private final java.io.Reader in
      • prevLine

        private int prevLine
      • systemID

        final java.lang.String systemID
        The systemID of the resource being read. If the resource being read is virtual the value is set to CssLocaton.NO_SID
      • curChar

        int curChar
        The char that this reader is currently positioned at, or -1 if EOF is reached.
      • prevChar

        int prevChar
        The previous char, or 0 if curChar is the first character in the resource being read.
      • offset

        int offset
        The offset (in characters) of prevChar from the start of the resource being read.
      • line

        int line
        The current line in the resource being read
      • col

        int col
        The current column in the resource being read
    • Constructor Detail

      • CssReader

        CssReader​(java.io.Reader reader,
                  java.lang.String systemID,
                  int pushbackSize)
    • Method Detail

      • next

        int next()
          throws java.io.IOException
        Returns the next character in the stream and advances the readers position. If there are no more characters, -1 is returned the first time this method is invoked in that state; multiple invocations at EOF will yield an IllegalStateException.
        Throws:
        java.io.IOException
      • peek

        int peek()
          throws java.io.IOException
        Returns the next character in the stream without advancing the readers position. If there are no more characters, -1 is returned.
        Throws:
        java.io.IOException
      • peek

        int[] peek​(int n)
            throws java.io.IOException
        Returns the the next n characters in the stream without advancing the readers position.
        Parameters:
        n - the number of characters to read
        Returns:
        An array with guaranteed length n, with -1 being the value for all elements at and after EOF.
        Throws:
        java.io.IOException
      • at

        int at​(int n)
        throws java.io.IOException
        Peek and return the character at position n from current position, or -1 if EOF is reached before or at that position.
        Throws:
        java.io.IOException
      • collect

        int[] collect​(int n)
               throws java.io.IOException
        Reads forward and returns the the next n characters in the stream. Escapes are returned verbatim. At return, the reader is at positioned such that next() will return n+1 or EOF (-1).
        Parameters:
        n - the number of characters to read
        Returns:
        An array with guaranteed length n, with -1 being the value for all elements at and after EOF.
        Throws:
        java.io.IOException
      • forward

        CssReader forward​(com.google.common.base.CharMatcher matcher)
                   throws java.io.IOException
        Read forward until the next non-escaped character matches the given CharMatcher or is EOF.
        Throws:
        java.io.IOException
      • forward

        CssReader forward​(int n)
                   throws java.io.IOException
        Read forward n characters, or until the next character is EOF.
        Throws:
        java.io.IOException
      • unread

        void unread​(int[] cbuf,
                    CssReader.Mark mark)
             throws java.io.IOException
        Throws:
        java.io.IOException
      • unread

        void unread​(java.util.List<java.lang.Integer> cbuf,
                    CssReader.Mark mark)
             throws java.io.IOException
        Throws:
        java.io.IOException
      • unread

        void unread​(int[] cbuf,
                    int off,
                    int len,
                    CssReader.Mark mark)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object