Package com.stardog.stark.io

# Class RDFWriters

java.lang.Object
com.stardog.stark.io.RDFWriters

public final class RDFWriters extends Object

Utility methods for working with `RDFWriter`

Since:
  1.0
Version:
  1.0
Author:
  Michael Grove

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static final class`
  `RDFWriters.RDFWriterConfig`
  Write builder for `RDFWriter`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static RDFWriters.RDFWriterConfig`
  `to(OutputStream theStream)`
  `static Optional<RDFWriter>`
  `to(OutputStream theOutput, RDFFormat theFormat)`
  Create a new `writer` to write in the specified `format` with the `default options`.
  `static Optional<RDFWriter>`
  `to(OutputStream theOutput, RDFFormat theFormat, Options theWriterOptions)`
  Create a new `writer` to write in the specified `format` with the given options.
  `static Optional<RDFWriter>`
  `to(OutputStream theOutput, RDFFormat theFormat, Iterable<Namespace> theNamespaces)`
  Create a new `writer` to write in the specified `format` with the given namespaces.
  `static String`
  `toString(Iterable<Statement> theStatements, RDFFormat theFormat)`
  Serialize the statements in the given `format` as a `String`.
  `static String`
  `toString(Iterable<Statement> theStatements, RDFFormat theFormat, Iterable<Namespace> theNamespaces)`
  Serialize the statements in the given `format` as a `String`.
  `static long`
  `write(RDFWriter theWriter, Iterable<Statement> theStmts)`
  Write the given statements to the `writer`
  `static long`
  `write(RDFWriter theWriter, Iterable<Statement> theStmts, Iterable<Namespace> theNamespaces)`
  Write the given statements and namespaces to the `writer`
  `static long`
  `write(OutputStream theStream, RDFFormat theFormat, Iterable<Statement> theStmts)`
  Writes the statements similar to `write(RDFWriter, Iterable, Iterable)`.
  `static long`
  `write(OutputStream theStream, RDFFormat theFormat, Iterable<Statement> theStmts, Iterable<Namespace> theNamespaces)`
  Writes the statements similar to `write(RDFWriter, Iterable, Iterable)`.
  `static long`
  `writeGrouped(RDFWriter theWriter, Iterable<Statement> theStmts, 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).
  `static long`
  `writeGrouped(OutputStream theStream, RDFFormat theFormat, Iterable<Statement> theStmts, 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).

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

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

- ## Method Details

  - ### to

    public static Optional<RDFWriter> to(@Nonnull 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 Optional<RDFWriter> to(@Nonnull OutputStream theOutput, @Nonnull RDFFormat theFormat, @Nonnull 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 Optional<RDFWriter> to(@Nonnull 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 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 Iterable<Statement> theStmts, @Nonnull 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 OutputStream theStream, @Nonnull RDFFormat theFormat, @Nonnull 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:
      `IllegalArgumentException` - if a writer supporting the given format is not found

  - ### write

    public static long write(@Nonnull OutputStream theStream, @Nonnull RDFFormat theFormat, @Nonnull Iterable<Statement> theStmts, @Nonnull 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:
      `IllegalArgumentException` - if a writer supporting the given format is not found

  - ### writeGrouped

    public static long writeGrouped(@Nonnull OutputStream theStream, @Nonnull RDFFormat theFormat, @Nonnull Iterable<Statement> theStmts, @Nonnull 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 Iterable<Statement> theStmts, @Nonnull 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 String toString(@Nonnull 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 String toString(@Nonnull Iterable<Statement> theStatements, @Nonnull RDFFormat theFormat, @Nonnull 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

  - ### to

    public static RDFWriters.RDFWriterConfig to(OutputStream theStream)