Class RDFWriters


  • public final class RDFWriters
    extends java.lang.Object

    Utility methods for working with RDFWriter

    Since:
    1.0
    Version:
    1.0
    Author:
    Michael Grove
    • Method Detail

      • to

        public static java.util.Optional<RDFWriter> to​(@Nonnull
                                                       java.io.OutputStream theOutput,
                                                       @Nonnull
                                                       RDFFormat theFormat)
        Create a new writer to write in the specified format with the default options.
        Parameters:
        theOutput - the output to write to
        theFormat - the format to write in
        Returns:
        the `RDFWriter` to use for writing
        See Also:
        WriterOptions
        Implementation Notes:
        The `OutputStream` is *not* closed when writing is complete
      • to

        public static java.util.Optional<RDFWriter> to​(@Nonnull
                                                       java.io.OutputStream theOutput,
                                                       @Nonnull
                                                       RDFFormat theFormat,
                                                       @Nonnull
                                                       java.lang.Iterable<Namespace> theNamespaces)
        Create a new writer to write in the specified format with the given namespaces.
        Parameters:
        theOutput - the output to write to
        theFormat - the format to write in
        theNamespaces - the namespaces for writing
        Returns:
        the `RDFWriter` to use for writing
        See Also:
        WriterOptions
        Implementation Notes:
        The `OutputStream` is *not* closed when writing is complete
      • to

        public static java.util.Optional<RDFWriter> to​(@Nonnull
                                                       java.io.OutputStream theOutput,
                                                       @Nonnull
                                                       RDFFormat theFormat,
                                                       @Nonnull
                                                       Options theWriterOptions)
        Create a new writer to write in the specified format with the given options.
        Parameters:
        theOutput - the output to write to
        theFormat - the format to write in
        theWriterOptions - the options for writing
        Returns:
        the `RDFWriter` to use for writing
        See Also:
        WriterOptions
        Implementation Notes:
        The `OutputStream` is *not* closed when writing is complete
      • write

        public static long write​(@Nonnull
                                 RDFWriter theWriter,
                                 @Nonnull
                                 java.lang.Iterable<Statement> theStmts)
        Write the given statements to the writer
        Parameters:
        theWriter - the RDFWriter to write to
        theStmts - the statements to write
        Implementation Notes:
        The writer will be started and ended before and after writing the given statements.
      • write

        public static long write​(@Nonnull
                                 RDFWriter theWriter,
                                 @Nonnull
                                 java.lang.Iterable<Statement> theStmts,
                                 @Nonnull
                                 java.lang.Iterable<Namespace> theNamespaces)
        Write the given statements and namespaces to the writer
        Parameters:
        theWriter - the RDFWriter to write to
        theStmts - the statements to write
        theNamespaces - the namespaces to use for converting IRIs to QNames
        Implementation Notes:
        The writer will be started and ended before and after writing the given statements.
      • write

        public static long write​(@Nonnull
                                 java.io.OutputStream theStream,
                                 @Nonnull
                                 RDFFormat theFormat,
                                 @Nonnull
                                 java.lang.Iterable<Statement> theStmts)
        Writes the statements similar to write(RDFWriter, Iterable, Iterable).
        Returns:
        the number of statements written (duplicate statements will be counted as many times as they appear)
        Throws:
        java.lang.IllegalArgumentException - if a writer supporting the given format is not found
      • write

        public static long write​(@Nonnull
                                 java.io.OutputStream theStream,
                                 @Nonnull
                                 RDFFormat theFormat,
                                 @Nonnull
                                 java.lang.Iterable<Statement> theStmts,
                                 @Nonnull
                                 java.lang.Iterable<Namespace> theNamespaces)
        Writes the statements similar to write(RDFWriter, Iterable, Iterable).
        Returns:
        the number of statements written (duplicate statements will be counted as many times as they appear)
        Throws:
        java.lang.IllegalArgumentException - if a writer supporting the given format is not found
      • writeGrouped

        public static long writeGrouped​(@Nonnull
                                        java.io.OutputStream theStream,
                                        @Nonnull
                                        RDFFormat theFormat,
                                        @Nonnull
                                        java.lang.Iterable<Statement> theStmts,
                                        @Nonnull
                                        java.lang.Iterable<Namespace> theNamespaces)
        Writes the statements similar to write(RDFWriter, Iterable, Iterable) but first groups the statements by their subjects and predicates so the output will look better (if the writer supports this kind of optimization).
        Returns:
        the number of statements written (duplicate statements will be counted as many times as they appear)
      • writeGrouped

        public static long writeGrouped​(@Nonnull
                                        RDFWriter theWriter,
                                        @Nonnull
                                        java.lang.Iterable<Statement> theStmts,
                                        @Nonnull
                                        java.lang.Iterable<Namespace> theNamespaces)
        Writes the statements similar to write(RDFWriter, Iterable, Iterable) but first groups the statements by their subjects and predicates so the output will look better (if the writer supports this kind of optimization).
        Returns:
        the number of statements written (duplicate statements will be counted as many times as they appear)
      • toString

        @Nonnull
        public static java.lang.String toString​(@Nonnull
                                                java.lang.Iterable<Statement> theStatements,
                                                @Nonnull
                                                RDFFormat theFormat)
        Serialize the statements in the given format as a String.
        Parameters:
        theStatements - the statements to serialize
        theFormat - the RDF format to serialize into
        Returns:
        the statements serialized in the given RDF format
        See Also:
        RDFFormats
        Implementation Notes:
        Since this serializes the statements into a String in-memory, this is not suitable for serialization of large graphs
      • toString

        @Nonnull
        public static java.lang.String toString​(@Nonnull
                                                java.lang.Iterable<Statement> theStatements,
                                                @Nonnull
                                                RDFFormat theFormat,
                                                @Nonnull
                                                java.lang.Iterable<Namespace> theNamespaces)
        Serialize the statements in the given format as a String.
        Parameters:
        theStatements - the statements to serialize
        theFormat - the RDF format to serialize into
        theNamespaces - the namespaces to use for converting IRIs to QNames
        Returns:
        the statements serialized in the given RDF format
        See Also:
        RDFFormats
        Implementation Notes:
        Since this serializes the statements into a String in-memory, this is not suitable for serialization of large graphs