Class NTParser

  • All Implemented Interfaces:
    RDFParser
    Direct Known Subclasses:
    NQuadsParser

    public class NTParser
    extends java.lang.Object
    implements RDFParser

    Default implementation of a parser for the RDF NTriples syntax

    Since:
    1.0
    Version:
    1.0
    Author:
    Michael Grove
    Implementation Notes:
    non-final because it shares a lot of parsing code with nquads
    • Field Detail

      • LOGGER

        protected static final org.slf4j.Logger LOGGER
    • Constructor Detail

      • NTParser

        public NTParser()
    • Method Detail

      • format

        @Nonnull
        public RDFFormat format()
        The format this parser can parse
        Specified by:
        format in interface RDFParser
        Returns:
        the format
      • parse

        public void parse​(@Nonnull
                          java.io.InputStream theStream,
                          @Nonnull
                          RDFHandler theRDFHandler,
                          @Nonnull
                          Options theOptions)
                   throws java.io.IOException
        Parse the content
        Specified by:
        parse in interface RDFParser
        Parameters:
        theStream - the stream to read from
        theRDFHandler - the handler to pass parse events to
        theOptions - the parsing options
        Throws:
        java.io.IOException - if there was an error while reading from the stream
      • parse

        public void parse​(@Nonnull
                          IOParserContext theContext)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • parseSubject

        protected int parseSubject​(@Nonnull
                                   IOParserContext theContext,
                                   int ch)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • parsePredicate

        protected int parsePredicate​(@Nonnull
                                     IOParserContext theContext,
                                     int ch)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • parseObject

        protected int parseObject​(@Nonnull
                                  IOParserContext theContext,
                                  int ch)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • parseUriRef

        protected int parseUriRef​(@Nonnull
                                  IOParserContext theContext,
                                  int ch,
                                  java.lang.StringBuilder uriRef)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • parseNodeID

        protected int parseNodeID​(@Nonnull
                                  IOParserContext theContext,
                                  int c,
                                  @Nonnull
                                  java.lang.StringBuilder name)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • assertLineTerminates

        protected int assertLineTerminates​(@Nonnull
                                           IOParserContext theContext)
                                    throws java.io.IOException
        Verifies that there is only whitespace or comments until the end of the line.
        Throws:
        java.io.IOException
      • skipToEndOfLine

        protected int skipToEndOfLine​(@Nonnull
                                      IOParserContext theContext,
                                      int theChar)
                               throws java.io.IOException
        Reads characters from reader until the first EOL has been read. The EOL character or -1 is returned.
        Throws:
        java.io.IOException
      • skipLine

        protected int skipLine​(int theChar,
                               @Nonnull
                               IOParserContext theContext)
                        throws java.io.IOException
        Reads characters from reader until the first EOL has been read. The first character after the EOL is returned. In case the end of the character stream has been reached, -1 is returned.
        Throws:
        java.io.IOException
      • skipWhitespace

        protected int skipWhitespace​(@Nonnull
                                     IOParserContext theContext,
                                     int theChar)
                              throws java.io.IOException
        Reads characters from reader until it finds a character that is not a space or tab, and returns this last character code point. In case the end of the character stream has been reached, -1 is returned.
        Throws:
        java.io.IOException