final ByteArrayOutputStream out = new ByteArrayOutputStream();
final RDFWriter rdfWriter = rdfWriterFactory.getWriter(out);
final WriterConfig writerConfig = rdfWriter.getWriterConfig();
writerConfig.set(BasicWriterSettings.RDF_LANGSTRING_TO_LANG_LITERAL, true);
writerConfig.set(BasicWriterSettings.XSD_STRING_TO_PLAIN_LITERAL, true);
rdfWriter.handleNamespace("ex", ex);
rdfWriter.startRDF();
rdfWriter.handleStatement(st1);
rdfWriter.handleStatement(st2);
rdfWriter.handleStatement(st3);
rdfWriter.handleStatement(st4);