001/*
002 * The contents of this file are subject to the license and copyright
003 * detailed in the LICENSE and NOTICE files at the root of the source
004 * tree.
005 */
006package org.fcrepo.event.serialization;
007
008import java.io.ByteArrayOutputStream;
009import java.nio.charset.StandardCharsets;
010
011import org.apache.jena.rdf.model.Model;
012import org.fcrepo.kernel.api.observer.Event;
013
014/**
015 * Serialize a Event as Turtle
016 * @author acoburn
017 * @since 6/16/16
018 */
019public class TurtleSerializer implements EventSerializer {
020
021    /**
022     * Serialize a Event in RDF using Turtle syntax
023     * @param evt the Fedora event
024     * @return a string of RDF, using Turtle syntax
025     */
026    @Override
027    public String serialize(final Event evt) {
028        final Model model = EventSerializer.toModel(evt);
029        final ByteArrayOutputStream out = new ByteArrayOutputStream();
030        model.write(out, "TTL");
031        return out.toString(StandardCharsets.UTF_8);
032    }
033}