org.eclipse.rdf4j.rio.ntriples

## Class NTriplesParser

- java.lang.Object
- - org.eclipse.rdf4j.rio.helpers.AbstractRDFParser
  - - org.eclipse.rdf4j.rio.ntriples.NTriplesParser

- All Implemented Interfaces:
    RDFParser
  Direct Known Subclasses:
    NQuadsParser

      public class NTriplesParser
      extends AbstractRDFParser

  RDF parser for N-Triples files. A specification of NTriples can be found in this section of the RDF Test Cases document. This parser is not thread-safe, therefore its public methods are synchronized.
  Author:
    Arjohn Kampman

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface org.eclipse.rdf4j.rio.RDFParser

      `RDFParser.DatatypeHandling`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected long` | `lineNo`
    `protected Value` | `object`
    `protected IRI` | `predicate`
    `protected PushbackReader` | `reader`
    `protected Resource` | `subject`

    - ### Fields inherited from class org.eclipse.rdf4j.rio.helpers.AbstractRDFParser

      `rdfHandler, valueFactory`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `NTriplesParser()` Creates a new NTriplesParser that will use a `SimpleValueFactory` to create object for resources, bNodes and literals.
    `NTriplesParser(ValueFactory valueFactory)` Creates a new NTriplesParser that will use the supplied `ValueFactory` to create RDF model objects.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected int` | `assertLineTerminates(int c)` Verifies that there is only whitespace or comments until the end of the line.
    `protected void` | `clear()` Clears any information that has been collected while parsing.
    `protected Literal` | `createLiteral(String label, String lang, String datatype)`
    `protected IRI` | `createURI(String uri)` Creates a `IRI` object for the specified URI-string.
    `RDFFormat` | `getRDFFormat()` Gets the RDF format that this parser can parse.
    `Collection<RioSetting<?>>` | `getSupportedSettings()`
    `void` | `parse(InputStream in, String baseURI)` Parses the data from the supplied InputStream, using the supplied baseURI to resolve any relative URI references.
    `void` | `parse(Reader reader, String baseURI)` Parses the data from the supplied Reader, using the supplied baseURI to resolve any relative URI references.
    `protected int` | `parseNodeID(int c, StringBuilder name)`
    `protected int` | `parseObject(int c)`
    `protected int` | `parsePredicate(int c)`
    `protected int` | `parseSubject(int c)`
    `protected int` | `parseUriRef(int c, StringBuilder uriRef)`
    `protected int` | `peekCodePoint()` Peeks at the next Unicode code point without advancing the reader, and returns its value.
    `protected int` | `readCodePoint()` Reads the next Unicode code point.
    `protected void` | `reportError(Exception e, RioSetting<Boolean> setting)` Reports an error with associated line- and column number to the registered ParseErrorListener, if the given setting has been set to true.
    `protected void` | `reportError(String msg, RioSetting<Boolean> setting)` Overrides `AbstractRDFParser.reportError(String, RioSetting)`, adding line number information to the error.
    `protected void` | `reportFatalError(Exception e)` Overrides `AbstractRDFParser.reportFatalError(Exception)`, adding line number information to the error.
    `protected void` | `reportFatalError(String msg)` Overrides `AbstractRDFParser.reportFatalError(String)`, adding line number information to the error.
    `protected void` | `reportWarning(String msg)` Overrides `AbstractRDFParser.reportWarning(String)`, adding line number information to the error.
    `protected int` | `skipLine(int c)`
    `protected int` | `skipLine(int c, StringBuilder sb)` Reads characters from reader until the first EOL has been read.
    `protected int` | `skipToEndOfLine(int c)` Reads characters from reader until the first EOL has been read.
    `protected int` | `skipWhitespace(int c)` Reads characters from reader until it finds a character that is not a space or tab, and returns this last character code point.
    `protected void` | `throwEOFException()`
    `protected void` | `unread(int codePoint)` Pushes back a single code point by copying it to the front of the buffer.

    - ### Methods inherited from class org.eclipse.rdf4j.rio.helpers.AbstractRDFParser

      `clearBNodeIDMap, createBNode, createBNode, createLiteral, createLiteral, createNode, createNode, createStatement, createStatement, datatypeHandling, getNamespace, getParseErrorListener, getParseLocationListener, getParserConfig, getRDFHandler, initializeNamespaceTableFromConfiguration, preserveBNodeIDs, reportError, reportError, reportError, reportFatalError, reportFatalError, reportFatalError, reportLocation, reportWarning, resolveURI, set, setBaseURI, setBaseURI, setDatatypeHandling, setNamespace, setParseErrorListener, setParseLocationListener, setParserConfig, setPreserveBNodeIDs, setRDFHandler, setStopAtFirstError, setValueFactory, setVerifyData, stopAtFirstError, verifyData`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.eclipse.rdf4j.rio.RDFParser

      `parse, parse`

- - ### Field Detail

    - #### reader

          protected PushbackReader reader

    - #### lineNo

          protected long lineNo

    - #### subject

          protected Resource subject

    - #### predicate

          protected IRI predicate

    - #### object

          protected Value object

  - ### Constructor Detail

    - #### NTriplesParser

          public NTriplesParser()

      Creates a new NTriplesParser that will use a `SimpleValueFactory` to create object for resources, bNodes and literals.

    - #### NTriplesParser

          public NTriplesParser(ValueFactory valueFactory)

      Creates a new NTriplesParser that will use the supplied `ValueFactory` to create RDF model objects.
      Parameters:
        `valueFactory` - A ValueFactory.

  - ### Method Detail

    - #### getRDFFormat

          public RDFFormat getRDFFormat()

      Description copied from interface: `RDFParser`
      Gets the RDF format that this parser can parse.

    - #### parse

          public void parse(InputStream in,
                            String baseURI)
                     throws IOException,
                            RDFParseException,
                            RDFHandlerException

      Description copied from interface: `RDFParser`
      Parses the data from the supplied InputStream, using the supplied baseURI to resolve any relative URI references.
      Parameters:
        `in` - The InputStream from which to read the data.
        `baseURI` - The URI associated with the data in the InputStream. May be `null`. Parsers for syntax formats that do not support relative URIs will ignore this argument.

        Note that if the data contains an embedded base URI, that embedded base URI will overrule the value supplied here (see RFC 3986 section 5.1 for details).

      Throws:
        `IOException` - If an I/O error occurred while data was read from the InputStream.
        `RDFParseException` - If the parser has found an unrecoverable parse error.
        `RDFHandlerException` - If the configured statement handler has encountered an unrecoverable error.

    - #### parse

          public void parse(Reader reader,
                            String baseURI)
                     throws IOException,
                            RDFParseException,
                            RDFHandlerException

      Description copied from interface: `RDFParser`
      Parses the data from the supplied Reader, using the supplied baseURI to resolve any relative URI references.
      Parameters:
        `reader` - The Reader from which to read the data.
        `baseURI` - The URI associated with the data in the InputStream. May be `null`. Parsers for syntax formats that do not support relative URIs will ignore this argument.

        Note that if the data contains an embedded base URI, that embedded base URI will overrule the value supplied here (see RFC 3986 section 5.1 for details).

      Throws:
        `IOException` - If an I/O error occurred while data was read from the InputStream.
        `RDFParseException` - If the parser has found an unrecoverable parse error.
        `RDFHandlerException` - If the configured statement handler has encountered an unrecoverable error.

    - #### skipWhitespace

          protected int skipWhitespace(int c)
                                throws 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:
        `IOException`

    - #### assertLineTerminates

          protected int assertLineTerminates(int c)
                                      throws IOException,
                                             RDFParseException

      Verifies that there is only whitespace or comments until the end of the line.
      Throws:
        `IOException`
        `RDFParseException`

    - #### skipToEndOfLine

          protected int skipToEndOfLine(int c)
                                 throws IOException

      Reads characters from reader until the first EOL has been read. The EOL character or -1 is returned.
      Throws:
        `IOException`

    - #### skipLine

          protected int skipLine(int c,
                                 StringBuilder sb)
                          throws 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:
        `IOException`

    - #### skipLine

          protected int skipLine(int c)
                          throws IOException

      Throws:
        `IOException`

    - #### parseSubject

          protected int parseSubject(int c)
                              throws IOException,
                                     RDFParseException

      Throws:
        `IOException`
        `RDFParseException`

    - #### parsePredicate

          protected int parsePredicate(int c)
                                throws IOException,
                                       RDFParseException

      Throws:
        `IOException`
        `RDFParseException`

    - #### parseObject

          protected int parseObject(int c)
                             throws IOException,
                                    RDFParseException

      Throws:
        `IOException`
        `RDFParseException`

    - #### parseUriRef

          protected int parseUriRef(int c,
                                    StringBuilder uriRef)
                             throws IOException,
                                    RDFParseException

      Throws:
        `IOException`
        `RDFParseException`

    - #### parseNodeID

          protected int parseNodeID(int c,
                                    StringBuilder name)
                             throws IOException,
                                    RDFParseException

      Throws:
        `IOException`
        `RDFParseException`

    - #### peekCodePoint

          protected int peekCodePoint()
                               throws IOException

      Peeks at the next Unicode code point without advancing the reader, and returns its value.
      Returns:
        the next Unicode code point, or -1 if the end of the stream has been reached.
      Throws:
        `IOException`

    - #### unread

          protected void unread(int codePoint)
                         throws IOException

      Pushes back a single code point by copying it to the front of the buffer. After this method returns, a call to `readCodePoint()` will return the same code point c again.
      Parameters:
        `codePoint` - a single Unicode code point.
      Throws:
        `IOException`

    - #### createURI

          protected IRI createURI(String uri)
                           throws RDFParseException

      Description copied from class: `AbstractRDFParser`
      Creates a `IRI` object for the specified URI-string.
      Overrides:
        `createURI` in class `AbstractRDFParser`
      Throws:
        `RDFParseException`

    - #### readCodePoint

          protected int readCodePoint()
                               throws IOException

      Reads the next Unicode code point.
      Returns:
        the next Unicode code point, or -1 if the end of the stream has been reached.
      Throws:
        `IOException`

    - #### createLiteral

          protected Literal createLiteral(String label,
                                          String lang,
                                          String datatype)
                                   throws RDFParseException

      Throws:
        `RDFParseException`

    - #### reportWarning

          protected void reportWarning(String msg)

      Overrides `AbstractRDFParser.reportWarning(String)`, adding line number information to the error.
      Overrides:
        `reportWarning` in class `AbstractRDFParser`

    - #### reportError

          protected void reportError(String msg,
                                     RioSetting<Boolean> setting)
                              throws RDFParseException

      Overrides `AbstractRDFParser.reportError(String, RioSetting)`, adding line number information to the error.
      Overrides:
        `reportError` in class `AbstractRDFParser`
      Parameters:
        `msg` - The message to use for `ParseErrorListener.error(String, long, long)` and for `RDFParseException.RDFParseException(String, long, long)` .
        `setting` - The boolean setting that will be checked to determine if this is an issue that we need to look at at all. If this setting is true, then the error listener will receive the error, and if `ParserConfig.isNonFatalError(RioSetting)` returns true an exception will be thrown.
      Throws:
        `RDFParseException` - If `RioConfig.get(RioSetting)` returns true, and `ParserConfig.isNonFatalError(RioSetting)` returns true for the given setting.

    - #### reportError

          protected void reportError(Exception e,
                                     RioSetting<Boolean> setting)
                              throws RDFParseException

      Description copied from class: `AbstractRDFParser`
      Reports an error with associated line- and column number to the registered ParseErrorListener, if the given setting has been set to true.

      This method also throws an `RDFParseException` when the given setting has been set to `true` and it is not a nonFatalError.

      Overrides:
        `reportError` in class `AbstractRDFParser`
      Parameters:
        `e` - The exception whose message will be used for `ParseErrorListener.error(String, long, long)` and for `RDFParseException.RDFParseException(String, long, long)` .
        `setting` - The boolean setting that will be checked to determine if this is an issue that we need to look at at all. If this setting is true, then the error listener will receive the error, and if `ParserConfig.isNonFatalError(RioSetting)` returns true an exception will be thrown.
      Throws:
        `RDFParseException` - If `RioConfig.get(RioSetting)` returns true, and `ParserConfig.isNonFatalError(RioSetting)` returns true for the given setting.

    - #### reportFatalError

          protected void reportFatalError(String msg)
                                   throws RDFParseException

      Overrides `AbstractRDFParser.reportFatalError(String)`, adding line number information to the error.
      Overrides:
        `reportFatalError` in class `AbstractRDFParser`
      Throws:
        `RDFParseException`

    - #### reportFatalError

          protected void reportFatalError(Exception e)
                                   throws RDFParseException

      Overrides `AbstractRDFParser.reportFatalError(Exception)`, adding line number information to the error.
      Overrides:
        `reportFatalError` in class `AbstractRDFParser`
      Throws:
        `RDFParseException`

    - #### throwEOFException

          protected void throwEOFException()
                                    throws RDFParseException

      Throws:
        `RDFParseException`

    - #### clear

          protected void clear()

      Description copied from class: `AbstractRDFParser`
      Clears any information that has been collected while parsing. This method must be called by subclasses when finishing the parse process.
      Overrides:
        `clear` in class `AbstractRDFParser`

    - #### getSupportedSettings

          public Collection<RioSetting<?>> getSupportedSettings()

      Specified by:
        `getSupportedSettings` in interface `RDFParser`
      Overrides:
        `getSupportedSettings` in class `AbstractRDFParser`
      Returns:
        A collection of `RioSetting`s that are supported by this RDFParser.

Copyright © 2015-2021 Eclipse Foundation. All Rights Reserved.