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