Author: andy
Date: Tue Aug 26 19:32:34 2014
New Revision: 1620705

URL: http://svn.apache.org/r1620705
Log:
JENA-769 : StreamRDFWriter

Added:
    
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamOps.java   
(with props)
    
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFWriter.java
   (with props)
    
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFWriterFactory.java
   (with props)
Modified:
    jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/RDFDataMgr.java
    
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFLib.java
    
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/writer/NQuadsWriter.java
    
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/writer/NTriplesWriter.java
    
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/writer/WriterStream.java

Modified: jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/RDFDataMgr.java
URL: 
http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/RDFDataMgr.java?rev=1620705&r1=1620704&r2=1620705&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/RDFDataMgr.java 
(original)
+++ jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/RDFDataMgr.java Tue 
Aug 26 19:32:34 2014
@@ -78,10 +78,19 @@ public class RDFDataMgr
      */
     
     static Logger log = LoggerFactory.getLogger(RDFDataMgr.class) ;
-    private static String riotBase = "http://jena.apache.org/riot/"; ; 
-    private static String streamManagerSymbolStr = riotBase+"streamManager" ; 
-    public static Symbol streamManagerSymbol = 
Symbol.create(streamManagerSymbolStr) ; 
+    private static String riotBase = "http://jena.apache.org/riot/"; ;
     
+//    private static String dataStreamManagerSymbolStr = 
riotBase+"dataStreamManager" ; 
+//    public static Symbol dataStreamManagerSymbol = 
Symbol.create(dataStreamManagerSymbolStr) ;
+//    
+//    private static String StreamManagerSymbolStr = riotBase+"streamManager" ;
+//    /** @deprecated Use  {@linkplain #dataStreamManagerSymbol} */
+//    @Deprecated
+//    public static Symbol streamManagerSymbolOld = 
Symbol.create(riotBase+"streamManager") ;
+    
+      private static String StreamManagerSymbolStr = riotBase+"streamManager" ;
+      public static Symbol streamManagerSymbol = 
Symbol.create(riotBase+"streamManager") ;
+
     /** Read triples into a Model from the given location. 
      *  The syntax is detemined from input source URI (content negotiation or 
extension). 
      * @param model Destination for the RDF read.

Added: 
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamOps.java
URL: 
http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamOps.java?rev=1620705&view=auto
==============================================================================
--- 
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamOps.java 
(added)
+++ 
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamOps.java 
Tue Aug 26 19:32:34 2014
@@ -0,0 +1,148 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.riot.system;
+
+import java.util.Iterator ;
+import java.util.Map.Entry ;
+
+import com.hp.hpl.jena.graph.Graph ;
+import com.hp.hpl.jena.graph.Triple ;
+import com.hp.hpl.jena.shared.PrefixMapping ;
+import com.hp.hpl.jena.sparql.core.DatasetGraph ;
+import com.hp.hpl.jena.sparql.core.Quad ;
+
+/* TODO
+ * Split up StreamRDFLib into factory and operations
+ * Check start/finish policies.
+ * org.apache.jena.riot.stream?
+ * 
+ */
+
+
+/** Utilities for sending to StreamRDF.
+ *  Unless otherwise stated, send* operations do not call 
stream.start()/stream.finish()
+ *  whereas other operations do.
+ */
+
+public class StreamOps {
+    
+    /** Send a dataset to a StreamRDF as prefixes, triples and quads, enclosed 
in stream.start()/steram.finish() */
+    public static void datasetToStream(DatasetGraph datasetGraph, StreamRDF 
stream) {
+        stream.start() ;
+        sendDatasetToStream(datasetGraph, stream) ;
+        stream.finish() ;
+    }
+
+    /** Send the triples of graph and it's prefix mapping to a StreamRDF, 
enclosed in stream.start()/steram.finish() */
+    public static void graphToStream(Graph graph, StreamRDF stream) {
+        stream.start();
+        sendGraphToStream(graph, stream) ;
+        stream.finish() ;
+    }
+
+    /** Send a PrefixMap to a stream */
+    public static void sendPrefixesToStream(PrefixMap prefixMap, StreamRDF 
stream) {
+        for ( Entry<String, String> e : 
prefixMap.getMappingCopyStr().entrySet())
+            stream.prefix(e.getKey(), e.getValue()) ;
+    }
+    
+    public static void sendPrefixesToStream(PrefixMapping prefixMap, StreamRDF 
stream) {
+        for ( Entry<String, String> e : prefixMap.getNsPrefixMap().entrySet() )
+            stream.prefix(e.getKey(), e.getValue()) ;
+    }
+
+    /** Send a dataset graph to a stream with triples for the default graph
+     * and quads for the named graphs without prefixes
+     */
+    public static void sendTriplesQuadsToStream(DatasetGraph datasetGraph, 
StreamRDF stream) {
+        sendDatasetToStream(datasetGraph, stream, null) ;
+    }
+
+    /** Send a dataset to a StreamRDF as prefixes, triples and quads */
+    public static void sendDatasetToStream(DatasetGraph datasetGraph, 
StreamRDF stream) {
+        PrefixMap prefixMap = 
PrefixMapFactory.create(datasetGraph.getDefaultGraph().getPrefixMapping()) ;
+        sendDatasetToStream(datasetGraph, stream, prefixMap) ;
+    }
+
+    //        
+//    /** Send a dataset to a StreamRDF as triples and quads, using the 
xpelcitily given prefix map */
+//    public static void datasetToStream(DatasetGraph datasetGraph, StreamRDF 
stream, PrefixMap prefixMap) {
+//        
+//    }
+//    
+    /** Send a dataset to a StreamRDF as triples and quads, using the 
explicitly given prefix map */
+    public static void sendDatasetToStream(DatasetGraph datasetGraph, 
StreamRDF stream, PrefixMap prefixMap) {
+        if ( prefixMap != null )
+            sendPrefixesToStream(prefixMap, stream) ;
+
+        // Default graph
+        Iterator<Triple> iter1 = datasetGraph.getDefaultGraph().find(null, 
null, null) ;
+        StreamOps.sendTriplesToStream(iter1, stream) ;
+        
+        Iterator<Quad> iter2 = datasetGraph.findNG(null, null, null, null) ;
+        StreamOps.sendQuadsToStream(iter2, stream) ;
+    }
+
+    
+    /** Send the triples of graph and an explicitly given prefix mapping, to a 
StreamRDF */
+    public static void sendGraphToStream(Graph graph, StreamRDF stream) {
+        PrefixMap prefixMap = 
PrefixMapFactory.create(graph.getPrefixMapping()) ;
+        sendGraphToStream(graph, stream, prefixMap) ;
+    }
+    
+    /** Send the triples of graph and an explicitly given prefix mapping, to a 
StreamRDF */
+    public static void sendGraphToStream(Graph graph, StreamRDF stream, 
PrefixMap prefixMap) {
+        if ( prefixMap != null )
+            sendPrefixesToStream(graph.getPrefixMapping(), stream) ;
+        Iterator<Triple> iter = graph.find(null, null, null) ;
+        StreamOps.sendTriplesToStream(iter, stream) ;
+    }
+
+    /** Send the triples of graph to a StreamRDF (no prefix mapping) */
+    public static void sendTriplesToStream(Graph graph, StreamRDF stream) {
+        sendGraphToStream(graph, stream, null) ;
+    }
+
+    /** Set triples to a StreamRDF - does not call .start/.finish */ 
+    public static void sendTriplesToStream(Iterator<Triple> iter, StreamRDF 
dest)
+    {
+        for ( ; iter.hasNext() ; )
+        {
+            Triple t = iter.next() ;
+            dest.triple(t) ;
+        }
+    }
+
+    /** Send quads of a dataset (including default graph as quads) to a 
StreamRDF, without prefixes */
+    public static void sendQuadsToStream(DatasetGraph datasetGraph, StreamRDF 
stream) {
+        Iterator<Quad> iter2 = datasetGraph.find(null, null, null, null) ;
+        StreamOps.sendQuadsToStream(iter2, stream) ;
+    }
+
+    /** Set quads to a StreamRDF - does not call .start/.finish */ 
+    public static void sendQuadsToStream(Iterator<Quad> iter, StreamRDF dest)
+    {
+        for ( ; iter.hasNext() ; )
+        {
+            Quad q = iter.next() ;
+            dest.quad(q) ;
+        }
+    }
+
+}
\ No newline at end of file

Propchange: 
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamOps.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFLib.java
URL: 
http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFLib.java?rev=1620705&r1=1620704&r2=1620705&view=diff
==============================================================================
--- 
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFLib.java 
(original)
+++ 
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFLib.java 
Tue Aug 26 19:32:34 2014
@@ -26,7 +26,7 @@ import org.apache.jena.atlas.io.AWriter 
 import org.apache.jena.atlas.io.IO ;
 import org.apache.jena.atlas.lib.Sink ;
 import org.apache.jena.riot.lang.StreamRDFCounting ;
-import org.apache.jena.riot.out.CharSpace;
+import org.apache.jena.riot.out.CharSpace ;
 import org.apache.jena.riot.writer.WriterStreamRDFPlain ;
 
 import com.hp.hpl.jena.graph.Graph ;
@@ -72,25 +72,19 @@ public class StreamRDFLib
     
     public static StreamRDF dataset(DatasetGraph dataset)    { return new 
ParserOutputDataset(dataset) ; }
     
-    /** Set triples to a StreamRDF - does not call .start/.finish */ 
+    /** Set triples to a StreamRDF - does not call .start/.finish 
+     * @deprecated Use {@link 
StreamOps#triplesToStream(Iterator&lt;Triple&gt;, StreamRDF,)} instead*/ 
+    @SuppressWarnings("javadoc")
+    @Deprecated
     public static void triplesToStream(StreamRDF dest, Iterator<Triple> iter)
-    {
-        for ( ; iter.hasNext() ; )
-        {
-            Triple t = iter.next() ;
-            dest.triple(t) ;
-        }
-    }
+    { StreamOps.sendTriplesToStream(iter, dest) ; }
 
-    /** Set quads to a StreamRDF - does not call .start/.finish */ 
+    /** Set quads to a StreamRDF - does not call .start/.finish 
+     * @deprecated Use {@link StreamOps#quadsToStream(Iterator&lt;Quad&gt;, 
StreamRDF)} instead*/
+    @SuppressWarnings("javadoc")
+    @Deprecated
     public static void quadsToStream(StreamRDF dest, Iterator<Quad> iter)
-    {
-        for ( ; iter.hasNext() ; )
-        {
-            Quad q = iter.next() ;
-            dest.quad(q) ;
-        }
-    }
+    { StreamOps.sendQuadsToStream(iter, dest) ; }
     
     /** 
      * Output to a sink; prefix and base handled only within the parser.

Added: 
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFWriter.java
URL: 
http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFWriter.java?rev=1620705&view=auto
==============================================================================
--- 
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFWriter.java
 (added)
+++ 
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFWriter.java
 Tue Aug 26 19:32:34 2014
@@ -0,0 +1,300 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.riot.system;
+
+import java.io.OutputStream ;
+import java.util.Collection ;
+import java.util.Collections ;
+import java.util.HashMap ;
+import java.util.Map ;
+
+import org.apache.jena.atlas.io.AWriter ;
+import org.apache.jena.atlas.io.IO ;
+import org.apache.jena.riot.* ;
+import org.apache.jena.riot.out.CharSpace ;
+import org.apache.jena.riot.writer.WriterStreamRDFBlocks ;
+import org.apache.jena.riot.writer.WriterStreamRDFFlat ;
+import org.apache.jena.riot.writer.WriterStreamRDFPlain ;
+
+import com.hp.hpl.jena.graph.Graph ;
+import com.hp.hpl.jena.graph.Triple ;
+import com.hp.hpl.jena.sparql.core.DatasetGraph ;
+import com.hp.hpl.jena.sparql.core.Quad ;
+
+/** Write RDF in a streaming fashion.
+ *  {@linkplain RDFDataMgr} operations do not provide this guaranttee.
+ *  See {@linkplain  RDFWriterRegistry} for general purpose writers.
+ *  
+ * @see RDFDataMgr 
+ * @see RDFWriterRegistry 
+ */
+public class StreamRDFWriter {
+
+    private static StreamRDFWriterFactory streamWriterFactoryBlocks = new 
StreamRDFWriterFactory() {
+        @Override
+        public StreamRDF create(OutputStream output, RDFFormat format) {
+            return new WriterStreamRDFBlocks(output) ;
+        }
+    } ;
+    
+    private static StreamRDFWriterFactory streamWriterFactoryFlat = new 
StreamRDFWriterFactory() {
+        @Override
+        public StreamRDF create(OutputStream output, RDFFormat format) {
+            return new WriterStreamRDFFlat(output) ;
+        }
+    } ;
+    
+    private static StreamRDFWriterFactory streamWriterFactoryTriplesQuads = 
new StreamRDFWriterFactory() {
+        @Override
+        public StreamRDF create(OutputStream output, RDFFormat format) {
+            AWriter w = IO.wrapUTF8(output) ;
+            return new WriterStreamRDFPlain(w, CharSpace.UTF8) ;     // 
N-Quads and N-Triples.
+        }
+    } ;
+    
+    private static StreamRDFWriterFactory streamWriterFactoryTriplesQuadsAscii 
= new StreamRDFWriterFactory() {
+        @Override
+        public StreamRDF create(OutputStream output, RDFFormat format) {
+            AWriter w = IO.wrapUTF8(output) ;
+            return new WriterStreamRDFPlain(w, CharSpace.ASCII) ;     // 
N-Quads and N-Triples.
+        }
+    } ;
+    
+//    private static StreamWriterFactory streamWriterFactoryThrift = new 
StreamWriterFactory() {
+//        @Override
+//        public StreamRDF create(OutputStream output, RDFFormat format) {
+//            boolean withValues = JenaThrift.RDF_THRIFT_VALUES.equals(format) 
; 
+//            return BinRDF.streamToOutputStream(output, withValues) ;
+//        }
+//    } ;
+    
+    private static WriterRegistry<StreamRDFWriterFactory> registry = new 
WriterRegistry<>() ;
+
+    /** Register the default serialization for the language (replace any 
existing registration).
+     * @param lang      Languages
+     * @param format    The serialization forma to use when the language is 
used for writing.
+     */
+    public static void register(Lang lang, RDFFormat format) {
+        registry.register(lang, format) ;
+    }
+    
+    /** Register the serialization for datasets and it's associated factory
+     * @param serialization         RDFFormat for the output format.
+     * @param streamWriterFactory    Source of writer engines
+     */
+    public static void register(RDFFormat serialization, 
StreamRDFWriterFactory streamWriterFactory) {
+        registry.register(serialization, streamWriterFactory) ;
+    }
+    
+    /** Return the format registered as the default for the language */ 
+    public static RDFFormat defaultSerialization(Lang lang) {
+        return registry.defaultSerialization(lang) ;
+    }
+    
+    static {
+        register(Lang.TURTLE,       RDFFormat.TURTLE_BLOCKS) ;
+        register(Lang.TRIG,         RDFFormat.TRIG_BLOCKS) ;
+        register(Lang.NTRIPLES,     RDFFormat.NTRIPLES) ;
+        register(Lang.NQUADS,       RDFFormat.NQUADS) ;
+//        register(Lang.THRIFT,       RDFFormat.RDF_THRIFT) ;
+        
+        register(RDFFormat.TURTLE_BLOCKS,   streamWriterFactoryBlocks) ;
+        register(RDFFormat.TURTLE_FLAT,     streamWriterFactoryFlat) ;
+        register(RDFFormat.TRIG_BLOCKS,     streamWriterFactoryBlocks) ;
+        register(RDFFormat.TRIG_FLAT,       streamWriterFactoryFlat) ;
+        
+        register(RDFFormat.NTRIPLES,        streamWriterFactoryTriplesQuads) ;
+        register(RDFFormat.NTRIPLES_UTF8,   streamWriterFactoryTriplesQuads) ;
+        register(RDFFormat.NTRIPLES_ASCII,  
streamWriterFactoryTriplesQuadsAscii) ;
+
+        register(RDFFormat.NQUADS,          streamWriterFactoryTriplesQuads) ;
+        register(RDFFormat.NQUADS_UTF8,     streamWriterFactoryTriplesQuads) ;
+        register(RDFFormat.NQUADS_ASCII,    
streamWriterFactoryTriplesQuadsAscii) ;
+
+//        register(JenaThrift.RDF_THRIFT,          streamWriterFactoryThrift) ;
+//        register(JenaThrift.RDF_THRIFT_VALUES,   streamWriterFactoryThrift) ;
+    }
+
+    /** Get a StreamRDF destination that will output in syntax <tt>Lang</tt>
+     *  and is guaranteed to do so in a scaling, streaming fashion.    
+     * @param output OutputStream
+     * @param lang   The syntax 
+     * @return       StreamRDF
+     * @see StreamOps#graphToStream
+     * @see StreamOps#datasetToStream
+     */
+    public static StreamRDF getWriterStream(OutputStream output, Lang lang) {
+        RDFFormat fmt = registry.choose(lang) ;
+        return getWriterStream(output, fmt) ;
+    }
+
+    /** Get a StreamRDF destination that will output in syntax 
<tt>RDFFormat</tt>
+     *  and is guaranteed to do so in a scaling, streaming fashion.    
+     * @param output OutputStream
+     * @param format  The syntax (as an {@linkplain RDFFormat}) 
+     * @return       StreamRDF
+     * @see StreamOps#graphToStream
+     * @see StreamOps#datasetToStream
+     */
+    public static StreamRDF getWriterStream(OutputStream output, RDFFormat 
format) {
+        StreamRDFWriterFactory x = registry.get(format) ;
+        if ( x == null )
+            throw new RiotException("Failed to find a writer factory for 
"+format) ;
+        StreamRDF stream = x.create(output, format) ;
+        if ( ! RDFLanguages.isQuads(format.getLang()) )
+            // Only pass through triples.
+            stream = new StreamTriplesOnly(stream) ;
+        return stream ;
+    }
+    
+    public static boolean registered(Lang lang) {
+        RDFFormat fmt = registry.defaultSerialization(lang) ;
+        return registry.contains(fmt) ;
+    }
+    
+    public static boolean registered(RDFFormat format) {
+        return registry.contains(format) ;
+    }
+    
+    public static Collection<RDFFormat> registered() {
+       return Collections.unmodifiableSet(registry.formatRegistry.keySet()) ;
+    }
+    
+    /** Write a Graph in streaming fashion
+     * 
+     * @param output OutputStream
+     * @param graph  Graph to write
+     * @param lang   Syntax
+     */
+    public static void write(OutputStream output, Graph graph, Lang lang) {
+        RDFFormat fmt = registry.choose(lang) ;
+        write(output, graph, fmt) ;
+    }
+
+    /** Write a Graph in streaming fashion
+     * 
+     * @param output OutputStream
+     * @param graph  Graph to write
+     * @param lang   Syntax
+     */
+    public static void write(OutputStream output, Graph graph, RDFFormat lang) 
{
+        StreamRDF stream = getWriterStream(output, lang) ;
+        StreamOps.graphToStream(graph, stream) ;
+    }
+
+    /** Write a DatasetGraph in streaming fashion
+     *  
+     * @param output        OutputStream
+     * @param datasetGraph  DatasetGraph to write
+     * @param lang          Syntax
+     */
+    public static void write(OutputStream output, DatasetGraph datasetGraph, 
Lang lang) {
+        RDFFormat fmt = registry.choose(lang) ;
+        write(output, datasetGraph, fmt) ;
+    }
+
+    /** Write a DatasetGraph in streaming fashion
+     *  
+     * @param output        OutputStream
+     * @param datasetGraph  DatasetGraph to write
+     * @param format          Syntax
+     */
+    public static void write(OutputStream output, DatasetGraph datasetGraph, 
RDFFormat format) {
+        StreamRDF stream = getWriterStream(output, format) ;
+        StreamOps.datasetToStream(datasetGraph, stream) ;
+    }
+    
+    private static class StreamTriplesOnly extends StreamRDFWrapper {
+
+        public StreamTriplesOnly(StreamRDF sink) {
+            super(sink) ;
+        }
+        
+        @Override public void quad(Quad quad) {
+            if ( quad.isTriple() || quad.isDefaultGraph() || 
quad.isUnionGraph() ) {
+                triple(quad.asTriple()) ;
+            }
+        }
+        
+        @Override public void triple(Triple triple) 
+        { sink.triple(triple) ; }
+    }
+    
+    /** Writer registry */
+    public static class WriterRegistry<T> {
+        // But RDFWriterregistry is two registries with shared Map<Lang, 
RDFFormat>
+        // Coudl refator but the benefit is not so great.
+        
+        private Map<RDFFormat, T>     formatRegistry  = new HashMap<>() ;
+        private Map<Lang, RDFFormat>  langToFormat    = new HashMap<>() ;
+
+        /** Register the default serialization for the language (replace any 
existing registration).
+         * @param lang      Languages
+         * @param format    The serialization forma to use when the language 
is used for writing.
+         */
+        public void register(Lang lang, RDFFormat format)
+        {
+            //register(format) ;
+            langToFormat.put(lang, format) ;
+        }
+        
+        /** Register the serialization for datasets and it's associated factory
+         * @param serialization         RDFFormat for the output format.
+         * @param streamWriterFactory    Source of writer engines
+         */
+        public void register(RDFFormat serialization, T streamWriterFactory) {
+            formatRegistry.put(serialization, streamWriterFactory) ;
+        }
+        
+        /** Return the T for a given RDFFormat.
+         * @param serialization     RDFFormat for the output format.
+         * @return T                Registered thing or null. 
+         */
+        public T get(RDFFormat serialization) {
+            return formatRegistry.get(serialization) ;
+        }
+
+        /** Return true if the format is registered 
+         * 
+         * @param serialization
+         * @return boolean
+         */
+        public boolean contains(RDFFormat serialization) {
+            return formatRegistry.containsKey(serialization) ;
+        }
+
+        /** Return the format registered as the default for the language */ 
+        public RDFFormat defaultSerialization(Lang lang) {
+            return langToFormat.get(lang) ;
+        }
+        
+        /**
+         * @param lang
+         * @return The RDFFormat for the lang
+         * @throws  RiotException if there is no registered format
+         */
+        public RDFFormat choose(Lang lang) {
+            RDFFormat fmt = defaultSerialization(lang) ;
+            if ( fmt == null )
+                throw new RiotException("No serialization for language "+lang) 
;
+            return fmt ;
+        }
+    }
+}
+

Propchange: 
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFWriter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFWriterFactory.java
URL: 
http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFWriterFactory.java?rev=1620705&view=auto
==============================================================================
--- 
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFWriterFactory.java
 (added)
+++ 
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFWriterFactory.java
 Tue Aug 26 19:32:34 2014
@@ -0,0 +1,27 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.riot.system;
+
+import java.io.OutputStream ;
+
+import org.apache.jena.riot.RDFFormat ;
+
+public interface StreamRDFWriterFactory {
+    StreamRDF create(OutputStream output, RDFFormat format) ;
+}

Propchange: 
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFWriterFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/writer/NQuadsWriter.java
URL: 
http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/writer/NQuadsWriter.java?rev=1620705&r1=1620704&r2=1620705&view=diff
==============================================================================
--- 
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/writer/NQuadsWriter.java 
(original)
+++ 
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/writer/NQuadsWriter.java 
Tue Aug 26 19:32:34 2014
@@ -25,6 +25,7 @@ import java.util.Iterator ;
 import org.apache.jena.riot.Lang ;
 import org.apache.jena.riot.out.CharSpace ;
 import org.apache.jena.riot.system.PrefixMap ;
+import org.apache.jena.riot.system.StreamOps ;
 import org.apache.jena.riot.system.StreamRDF ;
 import org.apache.jena.riot.system.StreamRDFLib ;
 
@@ -59,7 +60,7 @@ public class NQuadsWriter extends Writer
     private static void write$(StreamRDF s, Iterator<Quad> iter)
     {
         s.start() ;
-        StreamRDFLib.quadsToStream(s, iter) ;
+        StreamOps.sendQuadsToStream(iter, s) ;
         s.finish();
     }
     

Modified: 
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/writer/NTriplesWriter.java
URL: 
http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/writer/NTriplesWriter.java?rev=1620705&r1=1620704&r2=1620705&view=diff
==============================================================================
--- 
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/writer/NTriplesWriter.java
 (original)
+++ 
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/writer/NTriplesWriter.java
 Tue Aug 26 19:32:34 2014
@@ -29,6 +29,7 @@ import org.apache.jena.atlas.io.IO ;
 import org.apache.jena.riot.Lang ;
 import org.apache.jena.riot.out.CharSpace ;
 import org.apache.jena.riot.system.PrefixMap ;
+import org.apache.jena.riot.system.StreamOps ;
 import org.apache.jena.riot.system.StreamRDF ;
 import org.apache.jena.riot.system.StreamRDFLib ;
 
@@ -63,7 +64,7 @@ public class NTriplesWriter extends Writ
     private static void write$(StreamRDF s, Iterator<Triple> iter)
     {
         s.start() ;
-        StreamRDFLib.triplesToStream(s, iter) ;
+        StreamOps.sendTriplesToStream(iter, s) ;
         s.finish();
     }
 

Modified: 
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/writer/WriterStream.java
URL: 
http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/writer/WriterStream.java?rev=1620705&r1=1620704&r2=1620705&view=diff
==============================================================================
--- 
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/writer/WriterStream.java 
(original)
+++ 
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/writer/WriterStream.java 
Tue Aug 26 19:32:34 2014
@@ -22,8 +22,8 @@ import java.util.Iterator ;
 import java.util.Map.Entry ;
 
 import org.apache.jena.riot.system.PrefixMap ;
+import org.apache.jena.riot.system.StreamOps ;
 import org.apache.jena.riot.system.StreamRDF ;
-import org.apache.jena.riot.system.StreamRDFLib ;
 
 import com.hp.hpl.jena.graph.Graph ;
 import com.hp.hpl.jena.graph.Triple ;
@@ -59,7 +59,7 @@ public class WriterStream
         dest.base(baseURI) ;
         writePrefixes(dest, prefixes) ;
         Iterator<Quad> iter = datasetGraph.find(null, null, null, null) ;
-        StreamRDFLib.quadsToStream(dest, iter) ;
+        StreamOps.sendQuadsToStream(iter, dest) ;
         finish(dest) ;
     }
 
@@ -69,7 +69,7 @@ public class WriterStream
         dest.base(baseURI) ;
         writePrefixes(dest, prefixes) ;
         Iterator<Triple> iter = graph.find(null, null, null) ;
-        StreamRDFLib.triplesToStream(dest, iter) ;
+        StreamOps.sendTriplesToStream(iter, dest) ;
         finish(dest) ;
     }
 }


Reply via email to