jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1452591 [1/4] - in /jena/branches/arq-riot-output: src-examples/arq/examples/riot/ src-examples/arq/examples/update/ src/main/java/com/hp/hpl/jena/sparql/engine/binding/ src/main/java/com/hp/hpl/jena/sparql/engine/optimizer/ src/main/java/...
Date Mon, 04 Mar 2013 23:22:55 GMT
Author: andy
Date: Mon Mar  4 23:22:53 2013
New Revision: 1452591

URL: http://svn.apache.org/r1452591
Log:
Initial integration.

Added:
    jena/branches/arq-riot-output/src-examples/arq/examples/riot/ExRIOT_out1.java
    jena/branches/arq-riot-output/src-examples/arq/examples/riot/ExRIOT_out2.java
    jena/branches/arq-riot-output/src-examples/arq/examples/riot/ExRIOT_out3.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/StringWriterI.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/WriterI.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/WriterIBase.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RDFFormat.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RDFFormatVariant.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RDFWriterMgr.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RDFWriterRegistry.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/WriterDatasetRIOT.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/WriterDatasetRIOTFactory.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/WriterGraphRIOT.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/WriterGraphRIOTFactory.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/WriterRIOT.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/adapters/AdapterRDFWriter.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/adapters/RDFWriterRIOT.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/other/
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/other/BatchedStreamRDF.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/other/GLib.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/other/StreamRDFBatchHandler.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/OutputUtils.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/system/IO_Jena2.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/system/RiotWriterLib.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/NQuadsWriter.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/NTriplesWriter.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/NullWriter.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/RDFJSONWriter.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/RDFXMLAbbrevWriter.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/RDFXMLPlainWriter.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/SinkEntityOutput.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/TriGWriter.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/TriGWriterBase.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/TriGWriterBlocks.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/TriGWriterFlat.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/TurtleShell.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/TurtleWriter.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/TurtleWriterBase.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/TurtleWriterBlocks.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/TurtleWriterFlat.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/WriterConst.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/WriterDatasetRIOTBase.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/WriterGraphRIOTBase.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/WriterStream.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/WriterStreamRDFBase.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/WriterStreamRDFBatched.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/WriterStreamRDFBlocks.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/WriterStreamRDFFlat.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/WriterStreamRDFTuples.java
    jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/writer/
    jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/writer/AbstractWriterTest.java
    jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/writer/TS_RiotWriter.java
    jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/writer/TestJenaWriters.java
    jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/writer/TestRiotWriterDataset.java
    jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/writer/TestRiotWriterGraph.java
    jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/writer/TestWriterRegistration.java
    jena/branches/arq-riot-output/testing/RIOT/Writer/
      - copied from r1443261, jena/Experimental/riot-output/testing/RIOT/Writer/
    jena/branches/arq-riot-output/testing/RIOT/Writer/README.txt
      - copied unchanged from r1447079, jena/Experimental/riot-output/testing/RIOT/Writer/README.txt
    jena/branches/arq-riot-output/testing/RIOT/Writer/writer-jena.ttl
      - copied unchanged from r1447079, jena/Experimental/riot-output/testing/RIOT/Writer/writer-jena.ttl
    jena/branches/arq-riot-output/testing/RIOT/Writer/writer-rt-17.ttl
      - copied unchanged from r1448354, jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-17.ttl
    jena/branches/arq-riot-output/testing/RIOT/Writer/writer-rt-20.trig
      - copied unchanged from r1444417, jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-20.trig
    jena/branches/arq-riot-output/testing/RIOT/Writer/writer-rt-21.trig
      - copied unchanged from r1444417, jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-21.trig
    jena/branches/arq-riot-output/testing/RIOT/Writer/writer-rt-22.trig
      - copied unchanged from r1444417, jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-22.trig
    jena/branches/arq-riot-output/testing/RIOT/Writer/writer-rt-23.trig
      - copied unchanged from r1444417, jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-23.trig
Modified:
    jena/branches/arq-riot-output/src-examples/arq/examples/update/UpdateExecuteOperations.java
    jena/branches/arq-riot-output/src-examples/arq/examples/update/UpdateProgrammatic.java
    jena/branches/arq-riot-output/src-examples/arq/examples/update/UpdateReadFromFile.java
    jena/branches/arq-riot-output/src/main/java/com/hp/hpl/jena/sparql/engine/binding/BindingOutputStream.java
    jena/branches/arq-riot-output/src/main/java/com/hp/hpl/jena/sparql/engine/optimizer/Pattern.java
    jena/branches/arq-riot-output/src/main/java/com/hp/hpl/jena/sparql/resultset/TSVOutput.java
    jena/branches/arq-riot-output/src/main/java/com/hp/hpl/jena/sparql/serializer/QuerySerializer.java
    jena/branches/arq-riot-output/src/main/java/com/hp/hpl/jena/sparql/sse/writers/WriterOp.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/IO.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/IndentedWriter.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/Writer2.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/lib/ListUtils.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RIOT.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RiotWriter.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/EscapeStr.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/NodeFmtLib.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/NodeFormatter.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/NodeFormatterBase.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/NodeFormatterNT.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/NodeFormatterTTL.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/SinkQuadOutput.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/SinkTripleOutput.java
    jena/branches/arq-riot-output/src/test/java/com/hp/hpl/jena/query/TestParameterizedSparqlString.java
    jena/branches/arq-riot-output/src/test/java/com/hp/hpl/jena/sparql/algebra/optimize/TestFilterTransform.java
    jena/branches/arq-riot-output/src/test/java/com/hp/hpl/jena/sparql/expr/TestExprLib.java
    jena/branches/arq-riot-output/src/test/java/com/hp/hpl/jena/sparql/function/user/TestUserDefinedFunctionFactory.java
    jena/branches/arq-riot-output/src/test/java/com/hp/hpl/jena/sparql/function/user/TestUserFunctionsInSparql.java
    jena/branches/arq-riot-output/src/test/java/com/hp/hpl/jena/sparql/graph/TestDatasets.java
    jena/branches/arq-riot-output/src/test/java/com/hp/hpl/jena/sparql/resultset/TestResultSetFormat2.java
    jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/TC_Riot.java
    jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/TestParserRegistry.java
    jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/lang/TestPipedRDFIterators.java
    jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/out/TestNodeFmt.java
    jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/web/TestWebContent.java

Added: jena/branches/arq-riot-output/src-examples/arq/examples/riot/ExRIOT_out1.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src-examples/arq/examples/riot/ExRIOT_out1.java?rev=1452591&view=auto
==============================================================================
--- jena/branches/arq-riot-output/src-examples/arq/examples/riot/ExRIOT_out1.java (added)
+++ jena/branches/arq-riot-output/src-examples/arq/examples/riot/ExRIOT_out1.java Mon Mar  4 23:22:53 2013
@@ -0,0 +1,52 @@
+/**
+ * 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 arq.examples.riot;
+
+import org.apache.jena.riot.* ;
+
+import com.hp.hpl.jena.rdf.model.Model ;
+
+/** Example writing a model with RIOT */
+public class ExRIOT_out1
+{
+    public static void main(String[] args)
+    {
+        RIOT.init() ;
+        RDFWriterRegistry.init() ;
+        
+        Model model = RDFDataMgr.loadModel("D.ttl") ;
+        
+        System.out.println() ;
+        System.out.println("#### ---- Write as Turtle") ;
+        System.out.println() ;
+        RDFWriterMgr.write(System.out, model, Lang.TURTLE) ;
+        
+        System.out.println() ;
+        System.out.println("#### ---- Write as Turtle (streaming)") ;
+        System.out.println() ;
+        RDFWriterMgr.write(System.out, model, RDFFormat.TURTLE_BLOCKS) ;
+        
+        System.out.println() ;
+        System.out.println("#### ---- Write as Turtle via model.write") ;
+        System.out.println() ;
+        model.write(System.out, "TTL") ;
+    }
+
+}
+

Added: jena/branches/arq-riot-output/src-examples/arq/examples/riot/ExRIOT_out2.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src-examples/arq/examples/riot/ExRIOT_out2.java?rev=1452591&view=auto
==============================================================================
--- jena/branches/arq-riot-output/src-examples/arq/examples/riot/ExRIOT_out2.java (added)
+++ jena/branches/arq-riot-output/src-examples/arq/examples/riot/ExRIOT_out2.java Mon Mar  4 23:22:53 2013
@@ -0,0 +1,50 @@
+/**
+ * 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 arq.examples.riot;
+
+import org.apache.jena.riot.* ;
+
+import com.hp.hpl.jena.query.Dataset ;
+import com.hp.hpl.jena.rdf.model.Model ;
+
+/** Other writer examples */
+public class ExRIOT_out2
+{
+    public static void main(String[] args)
+    {
+        RIOT.init() ;
+        RDFWriterRegistry.init() ;
+        
+        Model model = RDFDataMgr.loadModel("D.ttl") ;
+        System.out.println() ;
+        System.out.println("#### ---- Write as TriG") ;
+        System.out.println() ;
+        // This wil be the default graph of the dataset written.
+        RDFWriterMgr.write(System.out, model, Lang.TRIG) ;
+        
+        // Loading Turtle as Trig reads into the default graph.
+        Dataset dataset = RDFDataMgr.loadDataset("D.ttl") ;
+        System.out.println() ;
+        System.out.println("#### ---- Write as NQuads") ;
+        System.out.println() ;
+        RDFWriterMgr.write(System.out, dataset, Lang.NQUADS) ;
+    }
+
+}
+

Added: jena/branches/arq-riot-output/src-examples/arq/examples/riot/ExRIOT_out3.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src-examples/arq/examples/riot/ExRIOT_out3.java?rev=1452591&view=auto
==============================================================================
--- jena/branches/arq-riot-output/src-examples/arq/examples/riot/ExRIOT_out3.java (added)
+++ jena/branches/arq-riot-output/src-examples/arq/examples/riot/ExRIOT_out3.java Mon Mar  4 23:22:53 2013
@@ -0,0 +1,111 @@
+/**
+ * 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 arq.examples.riot;
+
+import java.io.OutputStream ;
+import java.io.Writer ;
+
+import org.apache.jena.atlas.io.IndentedWriter ;
+import org.apache.jena.riot.* ;
+import org.apache.jena.riot.adapters.RDFWriterRIOT ;
+import org.apache.jena.riot.system.PrefixMap ;
+import org.apache.jena.riot.system.RiotWriterLib ;
+import org.apache.jena.riot.writer.WriterGraphRIOTBase ;
+
+import com.hp.hpl.jena.graph.Graph ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.sparql.sse.SSE ;
+import com.hp.hpl.jena.sparql.util.Context ;
+
+/** Example of registering a new writer with RIOT */
+public class ExRIOT_out3
+{
+    // See also ExRIOT_5
+    public static void main(String[] args)
+    {
+        RIOT.init() ;
+        RDFWriterRegistry.init() ;
+        
+        System.out.println("## Example of a registering a new language with RIOT") ; 
+        System.out.println() ;
+        
+        // Register the language
+        Lang lang = LangBuilder.create("SSE", "text/x-sse").addFileExtensions("rsse").build() ;
+        RDFLanguages.register(lang) ;
+
+        // Create format and register the association of language and default format.
+        // We are creating only one format here but in geenral theer can be variants
+        // (e.g. TURTLE - pretty printed or streamed) 
+        RDFFormat format = new RDFFormat(lang) ;
+        RDFWriterRegistry.register(lang, format)  ;
+        
+        // Register the writer factory
+        RDFWriterRegistry.register(format, new SSEWriterFactory()) ;
+
+        // ---- Use the register writer
+        Model model = RDFDataMgr.loadModel("D.ttl") ;
+        // Write
+        System.out.println("## Write by format") ;
+        RDFWriterMgr.write(System.out, model, format) ;
+        System.out.println() ;
+        System.out.println("## Write by language") ;
+        RDFWriterMgr.write(System.out, model, lang) ;
+        
+        // ---- Register for use with Model.read
+        // because naming is explicit, need to register an adapter.  
+        IO_Jena.registerForModelWrite("SSE", RDFWriterSSE.class) ;
+        
+        // and use it
+        model.write(System.out, "SSE") ;
+    }
+    
+    static class SSEWriterFactory implements WriterGraphRIOTFactory
+    {
+        @Override
+        public WriterGraphRIOT create(RDFFormat syntaxForm)
+        {
+            return new SSEWriter() ;
+        }
+    }
+    
+    static class SSEWriter extends WriterGraphRIOTBase
+    {
+        // Ignore externally provided prefix map and baseURI
+        @Override
+        public void write(OutputStream out, Graph graph, PrefixMap prefixMap, String baseURI, Context context)
+        {
+            SSE.write(out, graph) ;
+        }
+
+        @Override
+        public Lang getLang()   { return  RDFLanguages.contentTypeToLang("text/x-sse") ; }
+
+        @Override
+        public void write(Writer out, Graph graph, PrefixMap prefixMap, String baseURI, Context context)
+        {
+            // Writers are discouraged : just hope the charset is UTF-8.
+            IndentedWriter x = RiotWriterLib.create(out) ;
+            SSE.write(x, graph) ;
+        }
+    }
+
+    // Model.write adapter - must be public.
+    public static class RDFWriterSSE extends RDFWriterRIOT { public RDFWriterSSE() { super("SSE") ; } } 
+}
+

Modified: jena/branches/arq-riot-output/src-examples/arq/examples/update/UpdateExecuteOperations.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src-examples/arq/examples/update/UpdateExecuteOperations.java?rev=1452591&r1=1452590&r2=1452591&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src-examples/arq/examples/update/UpdateExecuteOperations.java (original)
+++ jena/branches/arq-riot-output/src-examples/arq/examples/update/UpdateExecuteOperations.java Mon Mar  4 23:22:53 2013
@@ -19,14 +19,11 @@
 package arq.examples.update;
 
 import org.apache.jena.atlas.lib.StrUtils ;
-import org.apache.jena.riot.RiotWriter ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFWriterMgr ;
 
 import com.hp.hpl.jena.sparql.sse.SSE ;
-import com.hp.hpl.jena.update.GraphStore ;
-import com.hp.hpl.jena.update.GraphStoreFactory ;
-import com.hp.hpl.jena.update.UpdateAction ;
-import com.hp.hpl.jena.update.UpdateFactory ;
-import com.hp.hpl.jena.update.UpdateRequest ;
+import com.hp.hpl.jena.update.* ;
 
 /** Build an update request up out of indvidiual Updates specified as strings.
  *  See UpdatePorgrammatic for another way to build up a request. 
@@ -85,7 +82,6 @@ public class UpdateExecuteOperations
         System.out.println();
         
         System.out.println("# N-Quads: S P O G") ;
-        RiotWriter.writeNQuads(System.out, graphStore) ;
-
+        RDFWriterMgr.write(System.out, graphStore, Lang.NQUADS) ;
     }
 }

Modified: jena/branches/arq-riot-output/src-examples/arq/examples/update/UpdateProgrammatic.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src-examples/arq/examples/update/UpdateProgrammatic.java?rev=1452591&r1=1452590&r2=1452591&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src-examples/arq/examples/update/UpdateProgrammatic.java (original)
+++ jena/branches/arq-riot-output/src-examples/arq/examples/update/UpdateProgrammatic.java Mon Mar  4 23:22:53 2013
@@ -18,18 +18,15 @@
 
 package arq.examples.update;
 
-import org.apache.jena.riot.RiotWriter ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFWriterMgr ;
 
 import com.hp.hpl.jena.sparql.modify.request.Target ;
 import com.hp.hpl.jena.sparql.modify.request.UpdateCreate ;
 import com.hp.hpl.jena.sparql.modify.request.UpdateDrop ;
 import com.hp.hpl.jena.sparql.modify.request.UpdateLoad ;
 import com.hp.hpl.jena.sparql.sse.SSE ;
-import com.hp.hpl.jena.update.GraphStore ;
-import com.hp.hpl.jena.update.GraphStoreFactory ;
-import com.hp.hpl.jena.update.UpdateAction ;
-import com.hp.hpl.jena.update.UpdateFactory ;
-import com.hp.hpl.jena.update.UpdateRequest ;
+import com.hp.hpl.jena.update.* ;
 
 /** Build an update request up out of indvidiual Update objects, not by parsing.
  *  This is quite low-level.
@@ -56,7 +53,6 @@ public class UpdateProgrammatic
         System.out.println();
         
         System.out.println("# N-Quads: S P O G") ;
-        RiotWriter.writeNQuads(System.out, graphStore) ;
-
+        RDFWriterMgr.write(System.out, graphStore, Lang.NQUADS) ;
     }
 }

Modified: jena/branches/arq-riot-output/src-examples/arq/examples/update/UpdateReadFromFile.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src-examples/arq/examples/update/UpdateReadFromFile.java?rev=1452591&r1=1452590&r2=1452591&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src-examples/arq/examples/update/UpdateReadFromFile.java (original)
+++ jena/branches/arq-riot-output/src-examples/arq/examples/update/UpdateReadFromFile.java Mon Mar  4 23:22:53 2013
@@ -18,14 +18,11 @@
 
 package arq.examples.update;
 
-import org.apache.jena.riot.RiotWriter ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFWriterMgr ;
 
 import com.hp.hpl.jena.sparql.sse.SSE ;
-import com.hp.hpl.jena.update.GraphStore ;
-import com.hp.hpl.jena.update.GraphStoreFactory ;
-import com.hp.hpl.jena.update.UpdateAction ;
-import com.hp.hpl.jena.update.UpdateFactory ;
-import com.hp.hpl.jena.update.UpdateRequest ;
+import com.hp.hpl.jena.update.* ;
 
 /** Simple example of SPARQL/Update : read a update script from a file and execute it */ 
 public class UpdateReadFromFile
@@ -52,6 +49,6 @@ public class UpdateReadFromFile
         System.out.println();
         
         System.out.println("# N-Quads: S P O G") ;
-        RiotWriter.writeNQuads(System.out, graphStore) ;
+        RDFWriterMgr.write(System.out, graphStore, Lang.NQUADS) ;
     }
 }

Modified: jena/branches/arq-riot-output/src/main/java/com/hp/hpl/jena/sparql/engine/binding/BindingOutputStream.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/com/hp/hpl/jena/sparql/engine/binding/BindingOutputStream.java?rev=1452591&r1=1452590&r2=1452591&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/com/hp/hpl/jena/sparql/engine/binding/BindingOutputStream.java (original)
+++ jena/branches/arq-riot-output/src/main/java/com/hp/hpl/jena/sparql/engine/binding/BindingOutputStream.java Mon Mar  4 23:22:53 2013
@@ -18,28 +18,29 @@
 
 package com.hp.hpl.jena.sparql.engine.binding;
 
-import java.io.* ;
+import java.io.IOException ;
+import java.io.OutputStream ;
+import java.io.Writer ;
 import java.util.List ;
 import java.util.Map ;
 
-
-import com.hp.hpl.jena.graph.Node ;
-
 import org.apache.jena.atlas.io.IO ;
+import org.apache.jena.atlas.io.WriterI ;
 import org.apache.jena.atlas.iterator.Iter ;
 import org.apache.jena.atlas.lib.Sink ;
 import org.apache.jena.iri.IRI ;
 import org.apache.jena.riot.RiotException ;
 import org.apache.jena.riot.out.NodeFormatter ;
 import org.apache.jena.riot.out.NodeFormatterTTL ;
-import org.apache.jena.riot.system.PrefixMap;
+import org.apache.jena.riot.system.PrefixMap ;
 
+import com.hp.hpl.jena.graph.Node ;
 import com.hp.hpl.jena.sparql.core.Var ;
 
 /** Parser for the RDF Tuples language */
 public class BindingOutputStream implements Sink<Binding>
 {
-    private final Writer bw ;
+    private final WriterI bw ;
     private Binding lastBinding = null ;
     private List<Var> vars = null ;
     private PrefixMap pmap ;
@@ -70,7 +71,7 @@ public class BindingOutputStream impleme
     
     private BindingOutputStream(Writer out, List<Var> variables, PrefixMap prefixMapping)
     {
-        bw = out ;
+        bw = IO.wrap(out) ;
         vars = variables ;
         pmap = prefixMapping ;
         

Modified: jena/branches/arq-riot-output/src/main/java/com/hp/hpl/jena/sparql/engine/optimizer/Pattern.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/com/hp/hpl/jena/sparql/engine/optimizer/Pattern.java?rev=1452591&r1=1452590&r2=1452591&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/com/hp/hpl/jena/sparql/engine/optimizer/Pattern.java (original)
+++ jena/branches/arq-riot-output/src/main/java/com/hp/hpl/jena/sparql/engine/optimizer/Pattern.java Mon Mar  4 23:22:53 2013
@@ -58,7 +58,7 @@ public class Pattern implements Printabl
         out.print(objItem.toString()) ;
         out.print(")") ;
         out.print(" ") ;
-        out.print(weight) ;
+        out.print(Double.toString(weight)) ;
         out.print(")") ;
     }
 }

Modified: jena/branches/arq-riot-output/src/main/java/com/hp/hpl/jena/sparql/resultset/TSVOutput.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/com/hp/hpl/jena/sparql/resultset/TSVOutput.java?rev=1452591&r1=1452590&r2=1452591&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/com/hp/hpl/jena/sparql/resultset/TSVOutput.java (original)
+++ jena/branches/arq-riot-output/src/main/java/com/hp/hpl/jena/sparql/resultset/TSVOutput.java Mon Mar  4 23:22:53 2013
@@ -18,13 +18,13 @@
 
 package com.hp.hpl.jena.sparql.resultset;
 
-import java.io.BufferedWriter ;
 import java.io.IOException ;
 import java.io.OutputStream ;
-import java.io.Writer ;
 import java.util.ArrayList ;
 import java.util.List ;
 
+import org.apache.jena.atlas.io.IO ;
+import org.apache.jena.atlas.io.WriterI ;
 import org.apache.jena.atlas.lib.StrUtils ;
 import org.apache.jena.riot.out.NodeFormatterTTL ;
 
@@ -33,7 +33,6 @@ import com.hp.hpl.jena.query.ResultSet ;
 import com.hp.hpl.jena.sparql.ARQException ;
 import com.hp.hpl.jena.sparql.core.Var ;
 import com.hp.hpl.jena.sparql.engine.binding.Binding ;
-import com.hp.hpl.jena.util.FileUtils ;
 
 /**
  * Tab Separated Values.
@@ -52,57 +51,51 @@ public class TSVOutput extends OutputBas
     @Override
     public void format(OutputStream out, ResultSet resultSet)
     {
-        try {
-        	//Use a Turtle formatter to format terms
-        	NodeFormatterTTL formatter = new NodeFormatterTTL(null, null);
-        	
-            Writer w = FileUtils.asUTF8(out) ;
-            w = new BufferedWriter(w) ;
-            
-            String sep = null ;
-            List<String> varNames = resultSet.getResultVars() ;
-            List<Var> vars = new ArrayList<Var>(varNames.size()) ;
-            
-            // writes the variables on the first line
-            for( String v : varNames )
+        //Use a Turtle formatter to format terms
+        NodeFormatterTTL formatter = new NodeFormatterTTL(null, null);
+
+        WriterI w = IO.wrapUTF8(out) ; 
+
+        String sep = null ;
+        List<String> varNames = resultSet.getResultVars() ;
+        List<Var> vars = new ArrayList<Var>(varNames.size()) ;
+
+        // writes the variables on the first line
+        for( String v : varNames )
+        {
+            if ( sep != null )
+                w.write(sep) ;
+            else
+                sep = SEP ;
+            Var var = Var.alloc(v) ;
+            w.write(var.toString()) ; 
+            vars.add(var) ;
+        }
+        w.write(NL) ;
+
+        // writes one binding by line
+        for ( ; resultSet.hasNext() ; )
+        {
+            sep = null ;
+            Binding b = resultSet.nextBinding() ;
+
+            for( Var v : vars )
             {
                 if ( sep != null )
                     w.write(sep) ;
-                else
-                    sep = SEP ;
-                Var var = Var.alloc(v) ;
-                w.write(var.toString()) ; 
-                vars.add(var) ;
-            }
-            w.write(NL) ;
-            
-            // writes one binding by line
-            for ( ; resultSet.hasNext() ; )
-            {
-                sep = null ;
-                Binding b = resultSet.nextBinding() ;
-                
-                for( Var v : vars )
+                sep = SEP ;
+
+                Node n = b.get(v) ;
+                if ( n != null )
                 {
-                    if ( sep != null )
-                        w.write(sep) ;
-                    sep = SEP ;
-                    
-                    Node n = b.get(v) ;
-                    if ( n != null )
-                    {
-                        // This will not include a raw tab.
-                        formatter.format(w, n);
-                    }
+                    // This will not include a raw tab.
+                    formatter.format(w, n);
                 }
-                w.write(NL) ;
             }
-            
-            w.flush() ;
-        } catch (IOException ex)
-        {
-            throw new ARQException(ex) ;
+            w.write(NL) ;
         }
+
+        w.flush() ;
     }
 
     static final byte[] headerBytes = StrUtils.asUTF8bytes("?_askResult" + NL);

Modified: jena/branches/arq-riot-output/src/main/java/com/hp/hpl/jena/sparql/serializer/QuerySerializer.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/com/hp/hpl/jena/sparql/serializer/QuerySerializer.java?rev=1452591&r1=1452590&r2=1452591&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/com/hp/hpl/jena/sparql/serializer/QuerySerializer.java (original)
+++ jena/branches/arq-riot-output/src/main/java/com/hp/hpl/jena/sparql/serializer/QuerySerializer.java Mon Mar  4 23:22:53 2013
@@ -296,7 +296,7 @@ public class QuerySerializer implements 
         for ( Var v : variables )
         {
             out.print(" ") ;
-            out.print(v) ;
+            out.print(v.toString()) ;
         }
         out.print(" )") ;
         out.print(" {") ;

Modified: jena/branches/arq-riot-output/src/main/java/com/hp/hpl/jena/sparql/sse/writers/WriterOp.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/com/hp/hpl/jena/sparql/sse/writers/WriterOp.java?rev=1452591&r1=1452590&r2=1452591&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/com/hp/hpl/jena/sparql/sse/writers/WriterOp.java (original)
+++ jena/branches/arq-riot-output/src/main/java/com/hp/hpl/jena/sparql/sse/writers/WriterOp.java Mon Mar  4 23:22:53 2013
@@ -440,7 +440,7 @@ public class WriterOp
                     Var v = agg.getVar() ;
                     String str = agg.getAggregator().toPrefixString() ;
                     start() ;
-                    out.print(v) ;
+                    out.print(v.toString()) ;
                     out.print(" ") ;
                     out.print(str) ;
                     finish() ;

Modified: jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/IO.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/IO.java?rev=1452591&r1=1452590&r2=1452591&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/IO.java (original)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/IO.java Mon Mar  4 23:22:53 2013
@@ -128,11 +128,29 @@ public class IO
         return new BufferedWriter(w) ;
     }
 
+    /** Wrap in a general writer interface */ 
+    static public WriterI wrap(Writer w)            
+    { 
+        return Writer2.wrap(w) ;
+    }
+    
+    /** Wrap in a general writer interface */ 
+    static public WriterI wrapUTF8(OutputStream out)    { return wrap(asUTF8(out)); } 
+    
     /** Create a print writer that uses UTF-8 encoding */ 
-
     static public PrintWriter asPrintWriterUTF8(OutputStream out) {
         return new PrintWriter(asUTF8(out)); 
     }
+
+    public static void close(org.apache.jena.atlas.lib.Closeable resource)
+    {
+        resource.close() ;
+    }
+
+    public static void closeSilent(org.apache.jena.atlas.lib.Closeable resource)
+    {
+        try { resource.close(); } catch (Exception ex) { }
+    }
     
     public static void close(java.io.Closeable resource)
     {
@@ -148,6 +166,12 @@ public class IO
         try { resource.close(); } catch (IOException ex) { }
     }
     
+    public static void closeSilent(IndentedWriter resource)
+    {
+        if ( resource == null )
+            return ;
+        try { resource.close();  } catch (Exception ex) { }
+    }
 
     public static void exception(IOException ex)
     {
@@ -173,6 +197,13 @@ public class IO
         try { out.flush(); } catch (IOException ex) { exception(ex) ; } 
     }
 
+    public static void flush(WriterI out)
+    {
+        if ( out == null )
+            return ;
+        out.flush(); 
+    }
+
     private static final int BUFFER_SIZE = 8*1024 ; 
     
     public static byte[] readWholeFile(InputStream in) 

Modified: jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/IndentedWriter.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/IndentedWriter.java?rev=1452591&r1=1452590&r2=1452591&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/IndentedWriter.java (original)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/IndentedWriter.java Mon Mar  4 23:22:53 2013
@@ -24,12 +24,13 @@ import java.io.OutputStream ;
 import java.io.Writer ;
 
 import org.apache.jena.atlas.AtlasException ;
+import org.apache.jena.atlas.lib.Closeable ;
 
 /** A writer that records what the current indentation level is, and
  *  uses that to insert a prefix at each line. 
  *  It can also insert line numbers at the beginning of lines. */
 
-public class IndentedWriter
+public class IndentedWriter extends WriterIBase implements WriterI, Closeable
 {
     /** Stdout wrapped in an IndentedWriter - no line numbers */
     public static final IndentedWriter stdout = new IndentedWriter(System.out) ; 
@@ -84,33 +85,57 @@ public class IndentedWriter
         startingNewLine = true ;
     }
 
-    public void print(Object obj) 
+    @Override
+    public void print(String str) 
     {
-        String s = "null" ;
-        if ( obj != null )
-            s = obj.toString() ;
+        if ( str == null )
+            str = "null" ;
         if ( false )
         {
             // Don't check for embedded newlines.
-            write(s) ;
+            write$(str) ;
             return ;
         }
-        for ( int i = 0 ; i < s.length() ; i++ )
-            printOneChar(s.charAt(i)) ;
+        for ( int i = 0 ; i < str.length() ; i++ )
+            printOneChar(str.charAt(i)) ;
     }
     
+    @Override
     public void printf(String formatStr, Object... args)
     {
         print(format(formatStr, args)) ;
     }
     
+    @Override
     public void print(char ch) { printOneChar(ch) ; }
     
-    public void println(Object obj) { print(obj) ; newline() ; }
+    @Override
+    public void println(String str) { print(str) ; newline() ; }
     public void println(char ch)  { print(ch) ; newline() ; }
 
+    @Override
     public void println() { newline() ; }
     
+    @Override
+    public void print(char[] cbuf)
+    {
+        for ( int i = 0 ; i < cbuf.length ; i++ )
+            printOneChar(cbuf[i]) ;
+    }
+
+    /** Print a string N times */
+    public void print(String s, int n)
+    {
+        for ( int i = 0 ; i < n ; i++ ) print(s) ;
+    }
+
+    /** Print a char N times */
+    public void print(char ch, int n)
+    {
+        lineStart() ;
+        for ( int i = 0 ; i < n ; i++ ) printOneChar(ch) ;
+    }
+
     private char lastChar = '\0' ;
     // Worker
     private void printOneChar(char ch) 
@@ -132,29 +157,16 @@ public class IndentedWriter
             newline() ;
             return ;
         }
-        write(ch) ;
+        write$(ch) ;
         column += 1 ;
     }
 
-    private void write(char ch) 
+    private void write$(char ch) 
     { try { out.write(ch) ; } catch (IOException ex) { throw new AtlasException(ex) ; } }
     
-    private void write(String s) 
+    private void write$(String s) 
     { try { out.write(s) ; } catch (IOException ex) { throw new AtlasException(ex) ; } }
     
-    /** Print a string N times */
-    public void print(String s, int n)
-    {
-        for ( int i = 0 ; i < n ; i++ ) print(s) ;
-    }
-
-    /** Print a char N times */
-    public void print(char ch, int n)
-    {
-        lineStart() ;
-        for ( int i = 0 ; i < n ; i++ ) printOneChar(ch) ;
-    }
-    
     public void newline()
     {
         lineStart() ; 
@@ -162,7 +174,7 @@ public class IndentedWriter
         if ( endOfLineMarker != null )
             print(endOfLineMarker) ;
         if ( ! flatMode )
-            write('\n') ;
+            write$('\n') ;
         startingNewLine = true ;
         row++ ;
         column = 0 ;
@@ -179,7 +191,10 @@ public class IndentedWriter
             newline() ;
     }
     
+    @Override
     public void close() { try { out.close(); } catch (IOException ex) {} }
+    
+    @Override
     public void flush() { try { out.flush(); } catch (IOException ex) {} }
     
     /** Pad to the indent (if we are before it) */
@@ -209,7 +224,7 @@ public class IndentedWriter
         int spaces = col - column  ;
         for ( int i = 0 ; i < spaces ; i++ )
         {
-            write(' ') ;        // Always a space.
+            write$(' ') ;        // Always a space.
             column++ ;
         }
     }
@@ -221,7 +236,7 @@ public class IndentedWriter
         {
             for ( int i = column ; i < currentIndent ; i++ )
             {
-                write(padChar) ;
+                write$(padChar) ;
                 column++ ;
             }
         }
@@ -229,7 +244,7 @@ public class IndentedWriter
         {
             for ( int i = column ; i < currentIndent ; i += padString.length() )
             {
-                write(padString) ;
+                write$(padString) ;
                 column += padString.length() ;
             }
         }
@@ -303,9 +318,9 @@ public class IndentedWriter
         currentIndent -= x ;
     }
     
-    public void setUnitIndent(int x) { unitIndent = x ; }
-    public int  getUnitIndent() { return unitIndent ; }
-    public boolean atLineStart() { return startingNewLine ; }
+    public void setUnitIndent(int x)    { unitIndent = x ; }
+    public int  getUnitIndent()         { return unitIndent ; }
+    public boolean atLineStart()        { return startingNewLine ; }
     
     private void lineStart()
     {
@@ -313,7 +328,7 @@ public class IndentedWriter
         {
             if ( startingNewLine && row > 1 )
                 // Space between each line.
-                write(' ') ;
+                write$(' ') ;
             startingNewLine = false ;
             return ;
         }
@@ -334,9 +349,9 @@ public class IndentedWriter
             return ;
         String s = Integer.toString(row) ;
         for ( int i = 0 ; i < WidthLineNumber-s.length() ; i++ )
-            write(' ') ;
-        write(s) ;
-        write(' ') ;
+            write$(' ') ;
+        write$(s) ;
+        write$(' ') ;
     }
     
     @Override

Added: jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/StringWriterI.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/StringWriterI.java?rev=1452591&view=auto
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/StringWriterI.java (added)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/StringWriterI.java Mon Mar  4 23:22:53 2013
@@ -0,0 +1,30 @@
+/**
+ * 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.atlas.io;
+
+import java.io.StringWriter ;
+
+public class StringWriterI extends Writer2
+{
+    public StringWriterI()
+    {
+        super(new StringWriter()) ;
+    }
+}
+

Modified: jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/Writer2.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/Writer2.java?rev=1452591&r1=1452590&r2=1452591&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/Writer2.java (original)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/Writer2.java Mon Mar  4 23:22:53 2013
@@ -18,6 +18,7 @@
 
 package org.apache.jena.atlas.io;
 
+import java.io.BufferedWriter ;
 import java.io.IOException ;
 import java.io.Writer ;
 
@@ -25,36 +26,68 @@ import org.apache.jena.atlas.lib.Closeab
 
 /** A Writer, without the checked exceptions. */
 
-public final class Writer2 implements Closeable
+public class Writer2 extends WriterIBase implements WriterI, Closeable
 {
-    private final Writer writer ;
+    protected final Writer writer ;
 
-    public static Writer2 wrap(Writer writer) { return new Writer2(writer) ; }
-    
-    public Writer2(Writer writer) { this.writer = writer ; }
+    public static Writer2 wrap(Writer writer)
+    {
+        if ( ! ( writer instanceof BufferedWriter ) )
+            writer = new BufferedWriter(writer) ;
+        return new Writer2(writer) ;
+    }
     
+    protected Writer2(Writer writer) { this.writer = writer ; }
 
-    public void output(int ch)
-    { try { writer.write(ch) ; } catch (IOException ex) { IO.exception(ex) ; } }
+    @Override
+    public void print(char ch)
+    { 
+        try { writer.write(ch) ; } catch (IOException ex) { IO.exception(ex) ; }
+    }
 
-    public void output(String string)
-    { try { writer.write(string) ; } catch (IOException ex) { IO.exception(ex) ; } }
+    @Override
+    public void print(String string)
+    { 
+        try { writer.write(string) ; } catch (IOException ex) { IO.exception(ex) ; }
+    }
 
-    public void output(String string, int off, int len)
-    { try { writer.write(string, off, len) ; } catch (IOException ex) { IO.exception(ex) ; } }
-    
-    public void output(char[] cbuf)
-    { try { writer.write(cbuf) ; } catch (IOException ex) { IO.exception(ex) ; } }
+    @Override
+    public void print(char[] cbuf)
+    {
+        try { writer.write(cbuf) ; } catch (IOException ex) { IO.exception(ex) ; }
+    }
 
-    public void output(char[] cbuf, int off, int len)
-    { try { writer.write(cbuf, off, len) ; } catch (IOException ex) { IO.exception(ex) ; } }
-    
+    @Override
     public void flush()
-    { try { writer.flush() ; } catch (IOException ex) { IO.exception(ex) ; } }
+    {
+        try { writer.flush() ; } catch (IOException ex) { IO.exception(ex) ; }
+    }
 
     @Override
     public void close()
-    { try { writer.close() ; } catch (IOException ex) { IO.exception(ex) ; } }
+    {
+        try { writer.close() ; } catch (IOException ex) { IO.exception(ex) ; }
+    }
 
+    @Override
+    public void printf(String fmt, Object... args)
+    {
+        print(String.format(fmt, args)) ;
+    }
+
+    @Override
+    public void println(String obj)
+    {
+        print(obj) ; print("\n") ;
+    }
+
+    @Override
+    public void println()
+    {
+        print("\n") ;
+    }
+    
+    @Override
+    public String toString() { return writer.toString() ; }
 }
 

Added: jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/WriterI.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/WriterI.java?rev=1452591&view=auto
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/WriterI.java (added)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/WriterI.java Mon Mar  4 23:22:53 2013
@@ -0,0 +1,43 @@
+/**
+ * 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.atlas.io;
+
+import org.apache.jena.atlas.lib.Closeable ;
+
+
+/** Simple abstraction of a string/character output stream */
+
+public interface WriterI extends Closeable
+{
+    public void write(char ch) ;
+    public void write(char[] cbuf) ; 
+    public void write(String string) ;
+
+    public void print(char ch) ;
+    public void print(char[] cbuf) ; 
+    public void print(String string) ;
+    public void printf(String fmt, Object ...arg) ;
+    public void println(String object) ;
+    public void println() ;
+    
+    public void flush() ;
+    @Override
+    public void close() ;
+}
+

Added: jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/WriterIBase.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/WriterIBase.java?rev=1452591&view=auto
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/WriterIBase.java (added)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/io/WriterIBase.java Mon Mar  4 23:22:53 2013
@@ -0,0 +1,33 @@
+/**
+ * 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.atlas.io;
+
+
+/** Simple abstraction of a string/character output stream */
+
+public abstract class WriterIBase implements WriterI
+{
+    @Override
+    public final void write(char ch)          { print(ch) ; }
+    @Override
+    public final void write(char[] cbuf)      { print(cbuf) ; }
+    @Override
+    public final void write(String string)    { print(string) ; }
+}
+

Modified: jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/lib/ListUtils.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/lib/ListUtils.java?rev=1452591&r1=1452590&r2=1452591&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/lib/ListUtils.java (original)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/atlas/lib/ListUtils.java Mon Mar  4 23:22:53 2013
@@ -107,7 +107,7 @@ public class ListUtils
             public void apply(T item)
             {
                 if ( ! first ) out.print(sep) ;
-                out.print(item) ;
+                out.print(item.toString()) ;
                 first = false ;
             }
         } ;

Added: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RDFFormat.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RDFFormat.java?rev=1452591&view=auto
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RDFFormat.java (added)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RDFFormat.java Mon Mar  4 23:22:53 2013
@@ -0,0 +1,118 @@
+/**
+ * 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;
+
+import org.apache.jena.atlas.lib.Lib ;
+
+/** Constants for writable formats */  
+public class RDFFormat
+{
+    /** Pretty printing variant */
+    public static RDFFormatVariant PRETTY       = new RDFFormatVariant("pretty" ) ;
+    /** Print in blocks, typically all triples with teh same subject in an incoming triple/quad stream */
+    public static RDFFormatVariant BLOCKS       = new RDFFormatVariant("blocks" ) ;
+    /** Print out one per line */
+    public static RDFFormatVariant FLAT         = new RDFFormatVariant("flat" ) ;
+    
+    public static RDFFormat TURTLE_PRETTY       = new RDFFormat(Lang.TURTLE, PRETTY) ;
+    public static RDFFormat TURTLE              = TURTLE_PRETTY ;
+    public static RDFFormat TTL                 = TURTLE_PRETTY ;
+    public static RDFFormat TURTLE_BLOCKS       = new RDFFormat(Lang.TURTLE, BLOCKS) ;
+    public static RDFFormat TURTLE_FLAT         = new RDFFormat(Lang.TURTLE, FLAT) ;
+    
+    public static RDFFormat NTRIPLES            = new RDFFormat(Lang.NTRIPLES) ;
+    public static RDFFormat NT                  = NTRIPLES ;
+    
+    public static RDFFormat NQUADS              = new RDFFormat(Lang.NQUADS) ;
+    public static RDFFormat NQ                  = NQUADS ;
+    
+    public static RDFFormat TRIG_PRETTY         = new RDFFormat(Lang.TRIG, PRETTY) ;
+    public static RDFFormat TRIG                = TRIG_PRETTY ;
+    public static RDFFormat TRIG_BLOCKS         = new RDFFormat(Lang.TRIG, BLOCKS) ;
+    public static RDFFormat TRIG_FLAT           = new RDFFormat(Lang.TRIG, FLAT) ;
+    
+    /** RDF/XML ABBREV variant*/
+    public static RDFFormatVariant ABBREV       = new RDFFormatVariant("pretty" ) ;
+    /** Basic RDF/XML variant */
+    public static RDFFormatVariant PLAIN        = new RDFFormatVariant("plain" ) ;
+    
+    public static RDFFormat RDFXML_PRETTY       = new RDFFormat(Lang.RDFXML, ABBREV) ;
+    public static RDFFormat RDFXML_ABBREV       = RDFXML_PRETTY ;
+    public static RDFFormat RDFXML              = RDFXML_PRETTY ;
+    public static RDFFormat RDFXML_PLAIN        = new RDFFormat(Lang.RDFXML, PLAIN) ;
+    
+    public static RDFFormat RDFJSON             = new RDFFormat(Lang.RDFJSON) ;
+    
+    /** The "null" output format (a sink that prints nothing, usually quite efficiently) */
+    public static RDFFormat RDFNULL             = new RDFFormat(Lang.RDFNULL) ;
+
+    private final Lang lang ;
+    private final RDFFormatVariant variant ;
+
+    public RDFFormat(Lang lang) { this(lang, null) ; }
+    
+    public RDFFormat(Lang lang, RDFFormatVariant variant)
+    {
+        this.lang = lang ;
+        this.variant = variant ;
+    }
+
+    public Lang getLang()
+    {
+        return lang ;
+    }
+
+    public RDFFormatVariant getVariant()
+    {
+        return variant ;
+    }
+
+    @Override
+    public int hashCode()
+    {
+        final int prime = 31 ;
+        int result = 1 ;
+        result = prime * result + ((lang == null) ? 0 : lang.hashCode()) ;
+        result = prime * result + ((variant == null) ? 0 : variant.hashCode()) ;
+        return result ;
+    }
+
+    @Override
+    public boolean equals(Object obj)
+    {
+        if (this == obj) return true ;
+        if (obj == null) return false ;
+        if (getClass() != obj.getClass()) return false ;
+        RDFFormat other = (RDFFormat)obj ;
+        if ( ! Lib.equal(lang, other.lang) )
+            return false ;
+        if ( ! Lib.equal(variant, other.variant) )
+            return false ;
+        return true ;
+    }
+    
+    @Override
+    public String toString()
+    {
+        if ( variant == null )
+            return lang.getName() ;
+        return lang.getName()+"/"+variant ;
+    }
+}
+

Added: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RDFFormatVariant.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RDFFormatVariant.java?rev=1452591&view=auto
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RDFFormatVariant.java (added)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RDFFormatVariant.java Mon Mar  4 23:22:53 2013
@@ -0,0 +1,59 @@
+/**
+ * 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;
+
+import org.apache.jena.atlas.lib.Lib ;
+
+import com.hp.hpl.jena.sparql.util.Symbol ;
+
+public class RDFFormatVariant
+{
+    private final Symbol symbol ;
+    
+    public RDFFormatVariant(String name)
+    {
+        symbol = Symbol.create(name) ;
+    }
+
+    @Override
+    public int hashCode()
+    {
+        final int prime = 31 ;
+        int result = 1 ;
+        result = prime * result + ((symbol == null) ? 0 : symbol.hashCode()) ;
+        return result ;
+    }
+
+    @Override
+    public boolean equals(Object obj)
+    {
+        if (this == obj) return true ;
+        if (obj == null) return false ;
+        if (getClass() != obj.getClass()) return false ;
+        RDFFormatVariant other = (RDFFormatVariant)obj ;
+        if ( ! Lib.equal(symbol, other.symbol) ) return false ;
+        return true ;
+    }
+
+    @Override
+    public String toString()
+    {
+        return symbol.getSymbol() ;
+    }
+}

Added: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RDFWriterMgr.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RDFWriterMgr.java?rev=1452591&view=auto
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RDFWriterMgr.java (added)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RDFWriterMgr.java Mon Mar  4 23:22:53 2013
@@ -0,0 +1,331 @@
+/** ;
+ * 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;
+
+import java.io.OutputStream ;
+import java.io.StringWriter ;
+import java.io.Writer ;
+
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RiotException ;
+import org.apache.jena.riot.system.RiotWriterLib ;
+
+import com.hp.hpl.jena.graph.Graph ;
+import com.hp.hpl.jena.query.Dataset ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.sparql.core.DatasetGraph ;
+
+public class RDFWriterMgr
+{
+    /** Write the model to the output stream in the default serialization for the language.
+     * @param out       OutputStream
+     * @param model     Graph to write
+     * @param lang      Language for the seralization.
+     */
+    public static void write(OutputStream out, Model model, Lang lang)
+    {
+        write(out, model.getGraph(), lang) ;
+    }
+
+    /** Write the model to the output stream in the default serialization for the language.
+     * @param out           OutputStream
+     * @param model         Model to write
+     * @param serialization Serialization format
+     */
+    public static void write(OutputStream out, Model model, RDFFormat serialization)
+    {
+        write(out, model.getGraph(), serialization) ;
+    }
+    
+    /** Write the graph to the output stream in the default serialization for the language.
+     * @param out           OutputStream
+     * @param model         Model to write
+     * @param lang          Serialization format
+     */
+    public static void write(StringWriter out, Model model, Lang lang)
+    {
+        write(out, model.getGraph(), lang) ;
+    }
+    
+    /** Write the graph to the output stream in the default serialization for the language.
+     * @param out           OutputStream
+     * @param model         Model to write
+     * @param serialization Serialization format
+     */
+    public static void write(StringWriter out, Model model, RDFFormat serialization)
+    {
+        write(out, model.getGraph(), serialization) ;
+    }
+
+    /** Write the graph to the output stream in the default serialization for the language.
+     * @param out           OutputStream
+     * @param model         Model to write
+     * @param serialization Serialization format
+     * @deprecated Use of writers is deprecated - use an OutputStream
+     */
+    @Deprecated
+    public static void write(Writer out, Model model, RDFFormat serialization)
+    {
+        write(out, model.getGraph(), serialization) ;
+    }
+
+    /** Write the graph to the output stream in the default serialization for the language.
+     * @param out       OutputStream
+     * @param graph     Graph to write
+     * @param lang      Language for the seralization.
+     */
+    public static void write(OutputStream out, Graph graph, Lang lang)
+    {
+        RDFFormat serialization = RDFWriterRegistry.defaultSerialization(lang) ;
+        write(out, graph, serialization) ;
+    }
+
+    /** Write the graph to the output stream in the default serialization for the language.
+     * @param out           OutputStream
+     * @param graph         Graph to write
+     * @param serialization Serialization format
+     */
+    public static void write(OutputStream out, Graph graph, RDFFormat serialization)
+    {
+        write$(out, graph, serialization) ;
+    }
+
+    /** Write the graph to the output stream in the default serialization for the language.
+     * @param out           OutputStream
+     * @param graph         Graph to write
+     * @param lang          Serialization format
+     */
+    public static void write(StringWriter out, Graph graph, Lang lang)
+    {
+        // Only known reasonable use of a Writer
+        write$(out, graph, RDFWriterRegistry.defaultSerialization(lang)) ;
+    }
+
+    /** Write the graph to the output stream in the default serialization for the language.
+     * @param out           OutputStream
+     * @param graph         Graph to write
+     * @param serialization Serialization format
+     */
+    public static void write(StringWriter out, Graph graph, RDFFormat serialization)
+    {
+        // Only known reasonable use of a Writer
+        write$(out, graph, serialization) ;
+    }
+
+    /** Write the graph to the output stream in the default serialization for the language.
+     * @param out           OutputStream
+     * @param graph         Graph to write
+     * @param serialization Serialization format
+     * @deprecated Use of writers is deprecated - use an OutputStream
+     */
+    @Deprecated
+    public static void write(Writer out, Graph graph, RDFFormat serialization)
+    {
+        write$(out, graph, serialization) ;
+    }
+    
+    /** Write the Dataset to the output stream in the default serialization for the language.
+     * @param out       OutputStream
+     * @param dataset   Dataset to write
+     * @param lang      Language for the seralization.
+     */
+    public static void write(OutputStream out, Dataset dataset, Lang lang)
+    {
+        write(out, dataset.asDatasetGraph(), lang) ;
+    }
+
+    /** Write the graph to the output stream in the default serialization for the language.
+     * @param out           OutputStream
+     * @param dataset       Dataset to write
+     * @param serialization Serialization format
+     */
+    public static void write(OutputStream out, Dataset dataset, RDFFormat serialization)
+    {
+        write(out, dataset.asDatasetGraph(), serialization) ;
+    }
+
+    /** Write the graph to the output stream in the default serialization for the language.
+     * @param out           Writer
+     * @param dataset       Dataset to write
+     * @param serialization Serialization format
+     */
+    public static void write(StringWriter out, Dataset dataset, RDFFormat serialization)
+    {
+        write$(out, dataset.asDatasetGraph(), serialization) ;
+    }
+
+    /** Write the graph to the output stream in the default serialization for the language.
+     * @param out           StringWriter
+     * @param dataset       Dataset to write
+     * @param lang      Language for the seralization.
+     */
+    public static void write(StringWriter out, Dataset dataset, Lang lang)
+    {
+        RDFFormat serialization = RDFWriterRegistry.defaultSerialization(lang) ;
+        write$(out, dataset.asDatasetGraph(), serialization) ;
+    }
+
+    /** Write the graph to the output stream in the default serialization for the language.
+     * @param out           Writer
+     * @param dataset       Dataset to write
+     * @param serialization Serialization format
+     * @deprecated Use of writers is deprecated - use an OutputStream
+     */
+    @Deprecated
+    public static void write(Writer out, Dataset dataset, RDFFormat serialization)
+    {
+        write$(out, dataset.asDatasetGraph(), serialization) ;
+    }
+
+    /** Write the DatasetGraph to the output stream in the default serialization for the language.
+     * @param out       OutputStream
+     * @param dataset   DatasetGraph to write
+     * @param lang      Language for the seralization.
+     */
+    public static void write(OutputStream out, DatasetGraph dataset, Lang lang)
+    {
+        RDFFormat serialization = RDFWriterRegistry.defaultSerialization(lang) ;
+        write(out, dataset, serialization) ;
+    }
+
+    /** Write the graph to the output stream in the default serialization for the language.
+     * @param out           OutputStream
+     * @param dataset       DatasetGraph to write
+     * @param serialization Serialization format
+     */
+    public static void write(OutputStream out, DatasetGraph dataset, RDFFormat serialization)
+    {
+        write$(out, dataset, serialization) ;
+    }
+
+    /** Write the DatasetGraph to the output stream in the default serialization for the language.
+     * @param out       StringWriter
+     * @param dataset   DatasetGraph to write
+     * @param lang      Language for the seralization.
+     */
+    public static void write(StringWriter out, DatasetGraph dataset, Lang lang)
+    {
+        RDFFormat serialization = RDFWriterRegistry.defaultSerialization(lang) ;
+        write(out, dataset, serialization) ;
+    }
+
+    /** Write the graph to the output stream in the default serialization for the language.
+     * @param out           StringWriter
+     * @param dataset       DatasetGraph to write
+     * @param serialization Serialization format
+     */
+    public static void write(StringWriter out, DatasetGraph dataset, RDFFormat serialization)
+    {
+        write$(out, dataset, serialization) ;
+    }
+
+    /** Write the graph to the output stream in the default serialization for the language.
+     * @param out           Writer
+     * @param dataset       DatasetGraph to write
+     * @param serialization Serialization format
+     * @deprecated Use of writers is deprecated - use an OutputStream
+     */
+    @Deprecated
+    public static void write(Writer out, DatasetGraph dataset, RDFFormat serialization)
+    {
+        write$(out, dataset, serialization) ;
+    }
+
+    /** Create a writer for an RDF language
+     * @param lang   Language for the seralization.
+     * @return WriterGraphRIOT
+     */
+    
+    public static WriterGraphRIOT createGraphWriter(Lang lang)
+    {
+        RDFFormat serialization = RDFWriterRegistry.defaultSerialization(lang) ;
+        return createGraphWriter$(serialization) ;    
+    }
+    
+    /** Create a writer for an RDF language
+     * @param serialization Serialization format
+     * @return WriterGraphRIOT
+     */
+    public static WriterGraphRIOT createGraphWriter(RDFFormat serialization)
+    {
+        return createGraphWriter$(serialization) ;    
+    }
+
+    /** Create a writer for an RDF language
+     * @param lang   Language for the seralization.
+     * @return WriterGraphRIOT
+     */
+    
+    public static WriterDatasetRIOT createDatasetWriter(Lang lang)
+    {
+        RDFFormat serialization = RDFWriterRegistry.defaultSerialization(lang) ;
+        return createDatasetWriter$(serialization) ;    
+    }
+    
+    /** Create a writer for an RDF language
+     * @param serialization Serialization format
+     * @return WriterGraphRIOT
+     */
+    public static WriterDatasetRIOT createDatasetWriter(RDFFormat serialization)
+    {
+        return createDatasetWriter$(serialization) ;    
+    }
+    
+    private static WriterGraphRIOT createGraphWriter$(RDFFormat serialization)
+    {
+        WriterGraphRIOTFactory wf = RDFWriterRegistry.getWriterGraphFactory(serialization) ;
+        if ( wf == null )
+            throw new RiotException("No graph writer for "+serialization) ; 
+        return wf.create(serialization) ;
+    }
+
+    private static WriterDatasetRIOT createDatasetWriter$(RDFFormat serialization)
+    {
+        WriterDatasetRIOTFactory wf = RDFWriterRegistry.getWriterDatasetFactory(serialization) ;
+        if ( wf == null )
+            throw new RiotException("No dataset writer for "+serialization) ; 
+        return wf.create(serialization) ;
+    }
+
+    private static void write$(OutputStream out, Graph graph, RDFFormat serialization)
+    {
+        WriterGraphRIOT w = createGraphWriter$(serialization) ;
+        w.write(out, graph, RiotWriterLib.prefixMap(graph), null, null) ;
+    }
+
+    private static void write$(Writer out, Graph graph, RDFFormat serialization)
+    {
+        WriterGraphRIOT w = createGraphWriter$(serialization) ;
+        w.write(out, graph, RiotWriterLib.prefixMap(graph), null, null) ;
+    }
+
+    private static void write$(OutputStream out, DatasetGraph dataset, RDFFormat serialization)
+    {
+        WriterDatasetRIOT w = createDatasetWriter$(serialization) ;
+        w.write(out, dataset, RiotWriterLib.prefixMap(dataset), null, null) ;
+    }
+
+    private static void write$(Writer out, DatasetGraph dataset, RDFFormat serialization)
+    {
+        WriterDatasetRIOT w = createDatasetWriter$(serialization) ;
+        w.write(out, dataset, RiotWriterLib.prefixMap(dataset), null, null) ;
+    }
+}
+

Added: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RDFWriterRegistry.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RDFWriterRegistry.java?rev=1452591&view=auto
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RDFWriterRegistry.java (added)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RDFWriterRegistry.java Mon Mar  4 23:22:53 2013
@@ -0,0 +1,228 @@
+/**
+ * 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;
+
+import java.util.Collection ;
+import java.util.Collections ;
+import java.util.HashMap ;
+import java.util.Map ;
+
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RIOT ;
+import org.apache.jena.riot.RiotException ;
+import org.apache.jena.riot.system.RiotWriterLib ;
+
+public class RDFWriterRegistry
+{
+    // All mention and use of Writers is purely for compatibility.
+    // They are not a good idea (StringWriter is an exception).
+    // Let the serializer deal with the character issues.
+    // UTF-8 is universal - but UTF-8 is not the default in Java ("platform encoding" is).
+    
+    static { RIOT.init() ; }
+
+    private static Map<RDFFormat, WriterGraphRIOTFactory> registryGraph     = new HashMap<RDFFormat, WriterGraphRIOTFactory>() ;
+    private static Map<RDFFormat, WriterDatasetRIOTFactory> registryDataset = new HashMap<RDFFormat, WriterDatasetRIOTFactory>() ;
+    private static Map<Lang, RDFFormat> langToFormat                        = new HashMap<Lang, RDFFormat>() ;
+    
+    // Writing a graph
+    static WriterGraphRIOTFactory wgfactory = new WriterGraphRIOTFactory() {
+        @Override
+        public WriterGraphRIOT create(RDFFormat serialization)
+        {
+            // Built-ins
+            if ( Lib.equal(RDFFormat.TURTLE_PRETTY, serialization) )
+                return RiotWriter.createTurtle() ;
+            if ( Lib.equal(RDFFormat.TURTLE_BLOCKS, serialization) )
+                return RiotWriter.createTurtleStreaming() ;
+            if ( Lib.equal(RDFFormat.TURTLE_FLAT, serialization) )
+                return RiotWriter.createTurtleFlat() ;
+            if ( Lib.equal(RDFFormat.NTRIPLES, serialization) )
+                return RiotWriter.createNTriples() ;
+            if ( Lib.equal(RDFFormat.RDFJSON, serialization) )
+                return RiotWriter.createRDFJSON() ;
+            if ( Lib.equal(RDFFormat.RDFXML_PRETTY, serialization) )
+                return RiotWriter.createRDFXMLAbbrev() ;
+            if ( Lib.equal(RDFFormat.RDFXML_PLAIN, serialization) )
+                return RiotWriter.createRDFXMLPlain() ;
+            
+            WriterDatasetRIOT dsw = wdsfactory.create(serialization) ;
+            if ( dsw != null )
+                return RiotWriterLib.adapter(dsw) ;
+            return null ;
+    }} ;
+        
+    
+    // Writing a dataset
+    static WriterDatasetRIOTFactory wdsfactory = new WriterDatasetRIOTFactory() {
+        @Override
+        public WriterDatasetRIOT create(RDFFormat serialization)
+        {
+            if ( Lib.equal(RDFFormat.TRIG_PRETTY, serialization) )
+                return RiotWriter.createTrig() ;
+            if ( Lib.equal(RDFFormat.TRIG_BLOCKS, serialization) )
+                return RiotWriter.createTrigStreaming() ;
+            if ( Lib.equal(RDFFormat.TRIG_FLAT, serialization) )
+                return RiotWriter.createTrigFlat() ;
+            if ( Lib.equal(RDFFormat.NQUADS, serialization) )
+                return RiotWriter.createNQuads() ;
+            if ( Lib.equal(RDFFormat.RDFNULL, serialization) )
+                return RiotWriter.createRDFNULL() ;
+            return null ;
+    }} ;
+
+     public static void init() {}
+     static { init$() ; }
+     private static void init$()
+     {
+         // Language to format.
+         register(Lang.TURTLE,      RDFFormat.TURTLE) ;
+         register(Lang.N3,          RDFFormat.TURTLE) ;
+         register(Lang.NTRIPLES,    RDFFormat.NTRIPLES) ;
+         register(Lang.RDFXML,      RDFFormat.RDFXML) ;
+         register(Lang.RDFJSON,     RDFFormat.RDFJSON) ;
+
+         register(Lang.TRIG,        RDFFormat.TRIG) ;
+         register(Lang.NQUADS,      RDFFormat.NQUADS) ;
+         register(Lang.RDFNULL,     RDFFormat.RDFNULL) ;
+
+         // Writer factories.
+         register(RDFFormat.TURTLE_PRETTY,  wgfactory) ;
+         register(RDFFormat.TURTLE_BLOCKS,  wgfactory) ;
+         register(RDFFormat.TURTLE_FLAT,    wgfactory) ;
+
+         register(RDFFormat.NTRIPLES,       wgfactory) ;
+         register(RDFFormat.RDFJSON,        wgfactory) ;
+
+         register(RDFFormat.RDFXML_PRETTY,  wgfactory) ;
+         register(RDFFormat.RDFXML_PLAIN,   wgfactory) ;
+
+         // Graphs in a quad format.
+         register(RDFFormat.TRIG_PRETTY,    wgfactory) ;
+         register(RDFFormat.TRIG_BLOCKS,    wgfactory) ;
+         register(RDFFormat.TRIG_FLAT,      wgfactory) ;
+
+         register(RDFFormat.NQUADS,         wgfactory) ;
+         register(RDFFormat.RDFNULL,        wgfactory) ;
+         
+         // Datasets
+         register(RDFFormat.TRIG_PRETTY,    wdsfactory) ;
+         register(RDFFormat.TRIG_BLOCKS,    wdsfactory) ;
+         register(RDFFormat.TRIG_FLAT,      wdsfactory) ;
+
+         register(RDFFormat.NQUADS,         wdsfactory) ;
+         register(RDFFormat.RDFNULL,        wdsfactory) ;
+     }
+    
+    /** Register the serialization for graphs and it's associated factory
+     * @param serialization         RDFFormat for the output format.
+     * @param graphWriterFactory    Source of writer engines
+     */
+    public static void register(RDFFormat serialization, WriterGraphRIOTFactory graphWriterFactory)
+    {
+        registryGraph.put(serialization, graphWriterFactory) ;
+    }
+
+    /** Register the serialization for datasets and it's associated factory
+     * @param serialization         RDFFormat for the output format.
+     * @param datasetWriterFactory    Source of writer engines
+     */
+    public static void register(RDFFormat serialization, WriterDatasetRIOTFactory datasetWriterFactory)
+    {
+        registryDataset.put(serialization, datasetWriterFactory) ;
+    }
+
+    /** Register an RDFFormat */
+    private static void register(RDFFormat serialization)
+    { }
+    
+    /** Register the default serialization for the language
+     * @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)
+    {
+        register(format) ;
+        langToFormat.put(lang, format) ;
+    }
+    
+    /** Return the format registered as the default for the language */ 
+    public static RDFFormat defaultSerialization(Lang lang)
+    {
+        return langToFormat.get(lang) ;
+    }
+
+    /** Does the language have a registerdd output format? */
+    public static boolean contains(Lang lang)
+    { 
+        if ( ! langToFormat.containsKey(lang) ) return false ;
+        
+        RDFFormat fmt = langToFormat.get(lang) ;
+        return contains(fmt) ;
+    }
+
+    /** Is the RDFFormat registered for use? */ 
+    public static boolean contains(RDFFormat format)
+    { return langToFormat.containsKey(format.getLang()) && (registryGraph.containsKey(format) || registryDataset.containsKey(format)); }
+
+
+    /** All registered graph formats */ 
+    public static Collection<RDFFormat> registeredGraphFormats() {
+        return Collections.unmodifiableSet(registryGraph.keySet()) ;
+    }
+
+    /** All registered dataset formats */ 
+    public static Collection<RDFFormat> registeredDatasetFormats() {
+        return Collections.unmodifiableSet(registryDataset.keySet()) ;
+    }
+    
+    /** Get the graph writer factory asscoiated with the language */
+    public static WriterGraphRIOTFactory getWriterGraphFactory(Lang lang)
+    {
+        RDFFormat serialization = defaultSerialization(lang) ;
+        if ( serialization == null )
+            throw new RiotException("No default serialization for language "+lang) ;
+        return getWriterGraphFactory(serialization) ;
+    }
+
+    /** Get the graph writer factory asscoiated with the output format */
+    public static WriterGraphRIOTFactory getWriterGraphFactory(RDFFormat serialization)
+    {
+        return registryGraph.get(serialization) ;
+    }
+    
+    /** Get the dataset writer factory asscoiated with the language */
+    public static WriterDatasetRIOTFactory getWriterDatasetFactory(Lang lang)
+    {
+        RDFFormat serialization = defaultSerialization(lang) ;
+        if ( serialization == null )
+            throw new RiotException("No default serialization for language "+lang) ;
+        return getWriterDatasetFactory(serialization) ;  
+    }
+
+    /** Get the dataset writer factory asscoiated with the output format */
+    public static WriterDatasetRIOTFactory getWriterDatasetFactory(RDFFormat serialization)
+    {
+        if ( serialization == null )
+            return null ; 
+        return registryDataset.get(serialization) ;
+    }
+}
+

Modified: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RIOT.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RIOT.java?rev=1452591&r1=1452590&r2=1452591&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RIOT.java (original)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RIOT.java Mon Mar  4 23:22:53 2013
@@ -19,6 +19,8 @@
 package org.apache.jena.riot;
 
 
+import org.apache.jena.riot.system.IO_Jena2 ;
+
 import com.hp.hpl.jena.query.ARQ ;
 import com.hp.hpl.jena.sparql.SystemARQ ;
 import com.hp.hpl.jena.sparql.mgt.ARQMgt ;
@@ -69,6 +71,10 @@ public class RIOT
             RDFParserRegistry.init() ;
             IO_Jena.wireIntoJena() ;
 
+            // Writers
+            RDFWriterRegistry.init() ;
+            IO_Jena2.wireIntoJenaW() ;
+            
             // Don't register JMX info with ARQ as it may not be initialized
             // itself and we can get into a circularity.
             // This is done in ARQ.init at the proper moment.



Mime
View raw message