Skip to content

Commit

Permalink
Control the output format manually
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Berezovskyi <[email protected]>
  • Loading branch information
berezovskyi committed Apr 13, 2024
1 parent 4c85b8e commit d921d87
Showing 1 changed file with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.RDFReaderI;
import org.apache.jena.rdf.model.RDFWriterI;
import org.apache.jena.riot.RDFDataMgr;
import org.apache.jena.riot.RDFFormat;
import org.apache.jena.riot.RDFLanguages;
import org.apache.jena.util.FileUtils;
import org.eclipse.lyo.oslc4j.core.OSLC4JConstants;
Expand Down Expand Up @@ -149,9 +151,13 @@ private void writeObjectsTo(final Object[] objects, final OutputStream outputStr
String xmlDeclaration = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
outputStream.write(xmlDeclaration.getBytes());
}
writer.write(model,
outputStream,
null);
if (writer instanceof RdfXmlAbbreviatedWriter) {
writer.write(model,
outputStream,
null);
} else {
RDFDataMgr.write(outputStream, model, resolveFormat(serializationLanguage));
}
Instant finish = Instant.now();
log.trace("writeObjectsTo - Execution Duration: {} ms", Duration.between(start, finish).toMillis());
}
Expand All @@ -162,7 +168,22 @@ private void writeObjectsTo(final Object[] objects, final OutputStream outputStr
}
}

private RDFWriterI getRdfWriter(final String serializationLanguage, final Model model) {
private RDFFormat resolveFormat(String serializationLanguage) {
switch (serializationLanguage) {
case RDFLanguages.strLangRDFXML:
return RDFFormat.RDFXML_PLAIN;
case RDFLanguages.strLangTurtle:
return RDFFormat.TURTLE_PRETTY;
case RDFLanguages.strLangNTriples:
return RDFFormat.NTRIPLES_UTF8;
case RDFLanguages.strLangJSONLD:
return RDFFormat.JSONLD10_COMPACT_PRETTY;
default:
throw new IllegalArgumentException();
}
}

private RDFWriterI getRdfWriter(final String serializationLanguage, final Model model) {
RDFWriterI writer;
if (serializationLanguage.equals(FileUtils.langXMLAbbrev))
{
Expand Down

0 comments on commit d921d87

Please sign in to comment.