Class NQuadsWriter

  • All Implemented Interfaces:
    com.apicatalog.rdf.api.RdfQuadConsumer

    public class NQuadsWriter
    extends java.lang.Object
    implements com.apicatalog.rdf.api.RdfQuadConsumer
    A writer for serializing RDF data in the N-Quads format.

    This class implements the RdfQuadConsumer interface, allowing RDF quads to be written to an output stream in the standard N-Quads serialization. It supports writing IRIs, blank nodes, literals, and language-tagged literals.

    See Also:
    RDF 1.1 N-Quads Specification
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.io.Writer writer  
    • Constructor Summary

      Constructors 
      Constructor Description
      NQuadsWriter​(java.io.Writer writer)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected static void literal​(java.io.Writer writer, java.lang.String object, java.lang.String datatype, java.lang.String langTag, java.lang.String direction)  
      static java.lang.String literal​(java.lang.String literal, java.lang.String datatype, java.lang.String langTag, java.lang.String direction)
      Formats an RDF literal with optional datatype, language tag, or direction.
      protected static void nquad​(java.io.Writer writer, java.lang.String subject, java.lang.String predicate, java.lang.String object, java.lang.String graph)  
      protected static void nquad​(java.io.Writer writer, java.lang.String subject, java.lang.String predicate, java.lang.String object, java.lang.String datatype, java.lang.String language, java.lang.String direction, java.lang.String graph)  
      static java.lang.String nquad​(java.lang.String subject, java.lang.String predicate, java.lang.String object, java.lang.String graph)
      Generates an N-Quad string representation for a quad with a resource subject, predicate, and object.
      static java.lang.String nquad​(java.lang.String subject, java.lang.String predicate, java.lang.String literal, java.lang.String datatype, java.lang.String graph)
      Generates an N-Quad string representation for a quad with a literal object and a specified datatype.
      static java.lang.String nquad​(java.lang.String subject, java.lang.String predicate, java.lang.String literal, java.lang.String language, java.lang.String direction, java.lang.String graph)
      Generates an N-Quad string representation for a quad with a lanauge-tagged literal object and optionally direction.
      static java.lang.String nquad​(java.lang.String subject, java.lang.String predicate, java.lang.String object, java.lang.String datatype, java.lang.String language, java.lang.String direction, java.lang.String graph)  
      com.apicatalog.rdf.api.RdfQuadConsumer quad​(java.lang.String subject, java.lang.String predicate, java.lang.String object, java.lang.String datatype, java.lang.String language, java.lang.String direction, java.lang.String graph)  
      static java.lang.String resource​(java.lang.String iri)
      Formats an IRI for use in N-Quads by enclosing it in angle brackets.
      static java.lang.String resourceOrBlank​(java.lang.String value)
      Converts an IRI or a blank node identifier into an N-Quads compliant representation.
      • Methods inherited from class java.lang.Object

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

      • writer

        protected final java.io.Writer writer
    • Constructor Detail

      • NQuadsWriter

        public NQuadsWriter​(java.io.Writer writer)
    • Method Detail

      • resourceOrBlank

        public static final java.lang.String resourceOrBlank​(java.lang.String value)
        Converts an IRI or a blank node identifier into an N-Quads compliant representation.
        Parameters:
        value - the IRI or blank node identifier to process
        Returns:
        the formatted IRI in angle brackets or the blank node identifier
        Throws:
        java.lang.IllegalArgumentException - if the input value is null
      • resource

        public static final java.lang.String resource​(java.lang.String iri)
        Formats an IRI for use in N-Quads by enclosing it in angle brackets.
        Parameters:
        iri - the IRI to format
        Returns:
        the IRI wrapped in angle brackets
        Throws:
        java.lang.IllegalArgumentException - if the input IRI is null
      • literal

        public static final java.lang.String literal​(java.lang.String literal,
                                                     java.lang.String datatype,
                                                     java.lang.String langTag,
                                                     java.lang.String direction)
        Formats an RDF literal with optional datatype, language tag, or direction.
        Parameters:
        literal - the literal value
        datatype - the optional datatype IRI (may be null)
        langTag - the optional language tag (may be null)
        direction - the optional text direction (may be null)
        Returns:
        the formatted N-Quads literal representation
        Throws:
        java.lang.IllegalArgumentException - if the literal value is null
      • nquad

        public static final java.lang.String nquad​(java.lang.String subject,
                                                   java.lang.String predicate,
                                                   java.lang.String object,
                                                   java.lang.String graph)
        Generates an N-Quad string representation for a quad with a resource subject, predicate, and object.
        Parameters:
        subject - The subject of the triple. This can be either an IRI or a blank node.
        predicate - The predicate of the triple, which must be an IRI.
        object - The object of the triple, which can be either an IRI or a blank node.
        graph - The named graph for the triple, or null if no graph is specified.
        Returns:
        The N-Quad representation of the triple as a string.
      • nquad

        public static final java.lang.String nquad​(java.lang.String subject,
                                                   java.lang.String predicate,
                                                   java.lang.String literal,
                                                   java.lang.String datatype,
                                                   java.lang.String graph)
        Generates an N-Quad string representation for a quad with a literal object and a specified datatype.
        Parameters:
        subject - The subject of the triple. This can be either an IRI or a blank node.
        predicate - The predicate of the triple, which must be an IRI.
        literal - The literal value for the object in the triple.
        datatype - The datatype IRI for the literal.
        graph - The named graph for the triple, or null if no graph is specified.
        Returns:
        The N-Quad representation of the triple as a string.
      • nquad

        public static final java.lang.String nquad​(java.lang.String subject,
                                                   java.lang.String predicate,
                                                   java.lang.String literal,
                                                   java.lang.String language,
                                                   java.lang.String direction,
                                                   java.lang.String graph)
        Generates an N-Quad string representation for a quad with a lanauge-tagged literal object and optionally direction.
        Parameters:
        subject - The subject of the triple. This can be either an IRI or a blank node.
        predicate - The predicate of the triple, which must be an IRI.
        literal - The literal value for the object in the triple.
        language - The language tag for the literal.
        direction - The direction of the literal, or null if not applicable.
        graph - The named graph for the triple, or null if no graph is specified.
        Returns:
        The N-Quad representation of the triple as a string.
      • nquad

        public static final java.lang.String nquad​(java.lang.String subject,
                                                   java.lang.String predicate,
                                                   java.lang.String object,
                                                   java.lang.String datatype,
                                                   java.lang.String language,
                                                   java.lang.String direction,
                                                   java.lang.String graph)
      • quad

        public com.apicatalog.rdf.api.RdfQuadConsumer quad​(java.lang.String subject,
                                                           java.lang.String predicate,
                                                           java.lang.String object,
                                                           java.lang.String datatype,
                                                           java.lang.String language,
                                                           java.lang.String direction,
                                                           java.lang.String graph)
                                                    throws com.apicatalog.rdf.api.RdfConsumerException
        Specified by:
        quad in interface com.apicatalog.rdf.api.RdfQuadConsumer
        Throws:
        com.apicatalog.rdf.api.RdfConsumerException
      • nquad

        protected static void nquad​(java.io.Writer writer,
                                    java.lang.String subject,
                                    java.lang.String predicate,
                                    java.lang.String object,
                                    java.lang.String graph)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • nquad

        protected static void nquad​(java.io.Writer writer,
                                    java.lang.String subject,
                                    java.lang.String predicate,
                                    java.lang.String object,
                                    java.lang.String datatype,
                                    java.lang.String language,
                                    java.lang.String direction,
                                    java.lang.String graph)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • literal

        protected static final void literal​(java.io.Writer writer,
                                            java.lang.String object,
                                            java.lang.String datatype,
                                            java.lang.String langTag,
                                            java.lang.String direction)
                                     throws java.io.IOException
        Throws:
        java.io.IOException