1414import java .io .OutputStream ;
1515import java .io .Reader ;
1616import java .io .Writer ;
17+ import java .net .URISyntaxException ;
1718import java .util .Optional ;
1819import java .util .function .Supplier ;
1920
@@ -138,6 +139,26 @@ public static RDFWriter createWriter(RDFFormat format, OutputStream out)
138139 return factory .getWriter (out );
139140 }
140141
142+ /**
143+ * Convenience methods for creating RDFWriter objects. This method uses the registry returned by
144+ * {@link RDFWriterRegistry#getInstance()} to get a factory for the specified format and uses this factory
145+ * to create the appropriate writer.
146+ *
147+ * @throws UnsupportedRDFormatException
148+ * If no writer is available for the specified RDF format.
149+ * @throws URISyntaxException
150+ * If the baseURI is invalid
151+ */
152+ public static RDFWriter createWriter (RDFFormat format , OutputStream out , String baseURI )
153+ throws UnsupportedRDFormatException ,
154+ URISyntaxException
155+ {
156+ RDFWriterFactory factory = RDFWriterRegistry .getInstance ().get (format ).orElseThrow (
157+ Rio .unsupportedFormat (format ));
158+
159+ return factory .getWriter (out , baseURI );
160+ }
161+
141162 /**
142163 * Convenience methods for creating RDFWriter objects. This method uses the registry returned by
143164 * {@link RDFWriterRegistry#getInstance()} to get a factory for the specified format and uses this factory
@@ -155,6 +176,26 @@ public static RDFWriter createWriter(RDFFormat format, Writer writer)
155176 return factory .getWriter (writer );
156177 }
157178
179+ /**
180+ * Convenience methods for creating RDFWriter objects. This method uses the registry returned by
181+ * {@link RDFWriterRegistry#getInstance()} to get a factory for the specified format and uses this factory
182+ * to create the appropriate writer.
183+ *
184+ * @throws UnsupportedRDFormatException
185+ * If no writer is available for the specified RDF format.
186+ * @throws URISyntaxException
187+ * If the baseURI is invalid
188+ */
189+ public static RDFWriter createWriter (RDFFormat format , Writer writer , String baseURI )
190+ throws UnsupportedRDFormatException ,
191+ URISyntaxException
192+ {
193+ RDFWriterFactory factory = RDFWriterRegistry .getInstance ().get (format ).orElseThrow (
194+ Rio .unsupportedFormat (format ));
195+
196+ return factory .getWriter (writer , baseURI );
197+ }
198+
158199 /**
159200 * Adds RDF data from an {@link InputStream} to a {@link Model}, optionally to one or more named contexts.
160201 *
@@ -325,6 +366,33 @@ public static void write(Iterable<Statement> model, OutputStream output, RDFForm
325366 write (model , output , dataFormat , new WriterConfig ());
326367 }
327368
369+ /**
370+ * Writes the given statements to the given {@link OutputStream} in the given format.
371+ * <p>
372+ * If the collection is a {@link Model}, its namespaces will also be written.
373+ *
374+ * @param model
375+ * A collection of statements, such as a {@link Model}, to be written.
376+ * @param output
377+ * The {@link OutputStream} to write the statements to.
378+ * @param baseURI
379+ * The base URI to relativize IRIs against.
380+ * @param dataFormat
381+ * The {@link RDFFormat} to use when writing the statements.
382+ * @throws RDFHandlerException
383+ * Thrown if there is an error writing the statements.
384+ * @throws URISyntaxException
385+ * If the baseURI is invalid
386+ * @throws UnsupportedRDFormatException
387+ * If no {@link RDFWriter} is available for the specified RDF format.
388+ */
389+ public static void write (Iterable <Statement > model , OutputStream output , String baseURI ,
390+ RDFFormat dataFormat )
391+ throws RDFHandlerException , UnsupportedRDFormatException , URISyntaxException
392+ {
393+ write (model , output , baseURI , dataFormat , new WriterConfig ());
394+ }
395+
328396 /**
329397 * Writes the given statements to the given {@link Writer} in the given format.
330398 * <p>
@@ -347,6 +415,32 @@ public static void write(Iterable<Statement> model, Writer output, RDFFormat dat
347415 write (model , output , dataFormat , new WriterConfig ());
348416 }
349417
418+ /**
419+ * Writes the given statements to the given {@link Writer} in the given format.
420+ * <p>
421+ * If the collection is a {@link Model}, its namespaces will also be written.
422+ *
423+ * @param model
424+ * A collection of statements, such as a {@link Model}, to be written.
425+ * @param output
426+ * The {@link Writer} to write the statements to.
427+ * @param baseURI
428+ * The base URI to relativize IRIs against.
429+ * @param dataFormat
430+ * The {@link RDFFormat} to use when writing the statements.
431+ * @throws RDFHandlerException
432+ * Thrown if there is an error writing the statements.
433+ * @throws URISyntaxException
434+ * If the baseURI is invalid
435+ * @throws UnsupportedRDFormatException
436+ * If no {@link RDFWriter} is available for the specified RDF format.
437+ */
438+ public static void write (Iterable <Statement > model , Writer output , String baseURI , RDFFormat dataFormat )
439+ throws RDFHandlerException , UnsupportedRDFormatException , URISyntaxException
440+ {
441+ write (model , output , baseURI , dataFormat , new WriterConfig ());
442+ }
443+
350444 /**
351445 * Writes the given statements to the given {@link OutputStream} in the given format.
352446 * <p>
@@ -374,6 +468,37 @@ public static void write(Iterable<Statement> model, OutputStream output, RDFForm
374468 write (model , writer );
375469 }
376470
471+ /**
472+ * Writes the given statements to the given {@link OutputStream} in the given format.
473+ * <p>
474+ * If the collection is a {@link Model}, its namespaces will also be written.
475+ *
476+ * @param model
477+ * A collection of statements, such as a {@link Model}, to be written.
478+ * @param output
479+ * The {@link OutputStream} to write the statements to.
480+ * @param baseURI
481+ * The base URI to relativize IRIs against.
482+ * @param dataFormat
483+ * The {@link RDFFormat} to use when writing the statements.
484+ * @param settings
485+ * The {@link WriterConfig} containing settings for configuring the writer.
486+ * @throws RDFHandlerException
487+ * Thrown if there is an error writing the statements.
488+ * @throws URISyntaxException
489+ * If the baseURI is invalid
490+ * @throws UnsupportedRDFormatException
491+ * If no {@link RDFWriter} is available for the specified RDF format.
492+ */
493+ public static void write (Iterable <Statement > model , OutputStream output , String baseURI ,
494+ RDFFormat dataFormat , WriterConfig settings )
495+ throws RDFHandlerException , UnsupportedRDFormatException , URISyntaxException
496+ {
497+ final RDFWriter writer = Rio .createWriter (dataFormat , output , baseURI );
498+ writer .setWriterConfig (settings );
499+ write (model , writer );
500+ }
501+
377502 /**
378503 * Writes the given statements to the given {@link Writer} in the given format.
379504 * <p>
@@ -401,6 +526,37 @@ public static void write(Iterable<Statement> model, Writer output, RDFFormat dat
401526 write (model , writer );
402527 }
403528
529+ /**
530+ * Writes the given statements to the given {@link Writer} in the given format.
531+ * <p>
532+ * If the collection is a {@link Model}, its namespaces will also be written.
533+ *
534+ * @param model
535+ * A collection of statements, such as a {@link Model}, to be written.
536+ * @param output
537+ * The {@link Writer} to write the statements to.
538+ * @param baseURI
539+ * The base URI to relativize IRIs against.
540+ * @param dataFormat
541+ * The {@link RDFFormat} to use when writing the statements.
542+ * @param settings
543+ * The {@link WriterConfig} containing settings for configuring the writer.
544+ * @throws RDFHandlerException
545+ * Thrown if there is an error writing the statements.
546+ * @throws URISyntaxException
547+ * If the baseURI is invalid
548+ * @throws UnsupportedRDFormatException
549+ * If no {@link RDFWriter} is available for the specified RDF format.
550+ */
551+ public static void write (Iterable <Statement > model , Writer output , String baseURI , RDFFormat dataFormat ,
552+ WriterConfig settings )
553+ throws RDFHandlerException , UnsupportedRDFormatException , URISyntaxException
554+ {
555+ final RDFWriter writer = Rio .createWriter (dataFormat , output , baseURI );
556+ writer .setWriterConfig (settings );
557+ write (model , writer );
558+ }
559+
404560 /**
405561 * Writes the given statements to the given {@link RDFHandler}.
406562 * <p>
0 commit comments