You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2013/03/05 00:22:55 UTC

svn commit: r1452591 [2/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/...

Modified: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RiotWriter.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RiotWriter.java?rev=1452591&r1=1452590&r2=1452591&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RiotWriter.java (original)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RiotWriter.java Mon Mar  4 23:22:53 2013
@@ -1,4 +1,4 @@
-/*
+/**
  * 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
@@ -21,34 +21,37 @@ package org.apache.jena.riot;
 import java.io.OutputStream ;
 import java.util.Iterator ;
 
-import org.apache.jena.riot.out.NQuadsWriter ;
-import org.apache.jena.riot.out.NTriplesWriter ;
-import org.apache.jena.riot.out.RDFJSONWriter ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.writer.* ;
 
 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 ;
 
-/** Output RDF in various formats (unfinished) */
+/** Direct call to create writers for specific formats.
+ *  The normal way to write is {@linkplain RDFWriterMgr} 
+ */
 public class RiotWriter
 {
-    // Work in progress
-    // A class of all the ways to write things - just jumps to right place in code. 
-    
+    // Compatibility stuff
+    /** @deprecated Use RDFWriterMgr.write(OutputStream, DatasetGraph, Lang.NQUADS) */
+    @Deprecated
     public static void writeNQuads(OutputStream out, DatasetGraph dsg)
     {
-        NQuadsWriter.write(out, dsg) ;
+        RDFWriterMgr.write(out, dsg, Lang.NQUADS) ;
     }
     
     public static void writeNQuads(OutputStream out, Iterator<Quad> it)
     {
         NQuadsWriter.write(out, it) ;
     }
-    
+
+    /** @deprecated Use RDFWriterMgr.write(OutputStream, Graph, Lang.NTRIPLES) */
+    @Deprecated
     public static void writeTriples(OutputStream out, Graph graph)
     {
-        NTriplesWriter.write(out, graph) ;
+        RDFWriterMgr.write(out, graph, Lang.NTRIPLES) ;
     }
     
     public static void writeTriples(OutputStream out, Iterator<Triple> it)
@@ -56,8 +59,177 @@ public class RiotWriter
         NTriplesWriter.write(out, it) ;
     }
 
+    /** @deprecated Use RDFWriterMgr.write(OutputStream, Graph, Lang.RDFJSON) */
+    @Deprecated
     public static void writeRDFJSON(OutputStream out, Graph graph)
     {
-    	RDFJSONWriter.write(out, graph) ;
+        RDFWriterMgr.write(out, graph, Lang.RDFJSON) ;
     }
+
+    // Remove after release ... no one should be using this code unless
+    // they used the off-trunk development code. 
+    
+//    /** Write as Turtle
+//     * @param out   OutputStream
+//     * @param model Model to write 
+//     */
+//    public static void writeTurtle(OutputStream out, Model model)
+//    { writeTurtle(out, model.getGraph()) ; }
+//    
+//    /** Write as Turtle
+//     * @param out   OutputStream
+//     * @param graph Graph to write 
+//     */
+//    public static void writeTurtle(OutputStream out, Graph graph)
+//    { createTurtle().write(out, graph) ; }
+//
+//    /** Write as Turtle, using a streaming writer
+//     * @param out   OutputStream
+//     * @param model Model to write 
+//     */
+//    public static void writeTurtleStreaming(OutputStream out,  Model model)
+//    { writeTurtleStreaming(out, model.getGraph()) ; }
+//    
+//    /** Write as Turtle, using a streaming writer
+//     * @param out   OutputStream
+//     * @param graph Graph to write 
+//     */
+//    public static void writeTurtleStreaming(OutputStream out, Graph graph)
+//    { createTurtleStreaming().write(out, graph) ; }
+//
+//    /** Write a model as NTriples
+//     * @param out       OutputStream
+//     * @param model     Model to write 
+//     */
+//    public static void writeNTriples(OutputStream out, Model model)
+//    { writeNTriples(out, model.getGraph()) ; }
+//    
+//    /** Write a graph as NTriples
+//     * @param out       OutputStream
+//     * @param graph     Graph to write 
+//     */
+//    public static void writeNTriples(OutputStream out, Graph graph)
+//    { createNTriples().write(out, graph) ; }
+//
+//    /** Write a model as RDF/XML
+//     * @param out       OutputStream
+//     * @param model     Model to write 
+//     */
+//    public static void writeRDFXML(OutputStream out, Model model)
+//    { writeRDFXML(out, model.getGraph()) ; }
+//    
+//    /** Write a graph as RDF/XML
+//     * @param out       OutputStream
+//     * @param graph     Graph to write 
+//     */
+//    public static void writeRDFXML(OutputStream out, Graph graph)
+//    { createRDFXMLAbbrev().write(out, graph) ; }
+//    
+//    /** Write a model as RDF/XML
+//     * @param out       OutputStream
+//     * @param model     Model to write 
+//     */
+//    public static void writeRDFXMLStreaming(OutputStream out, Model model)
+//    { writeRDFXMLStreaming(out, model.getGraph()) ; }
+//    
+//    /** Write a graph as RDF/XML
+//     * @param out       OutputStream
+//     * @param graph     Graph to write 
+//     */
+//    public static void writeRDFXMLStreaming(OutputStream out, Graph graph)
+//    { createRDFXMLPlain().write(out, graph) ; }
+//    
+//    /** Write a model as RDF/JSON (this is not JSON-LD)
+//     * @param out       OutputStream
+//     * @param model     Model to write 
+//     */
+//    public static void writeRDFJSON(OutputStream out, Model model)
+//    { writeRDFJSON(out, model.getGraph()) ; }
+//    
+//    /** Write a graph as RDF/JSON (this is not JSON-LD)
+//     * @param out       OutputStream
+//     * @param graph     Graph to write 
+//     */
+//    public static void writeRDFJSON(OutputStream out, Graph graph)
+//    { createRDFJSON().write(out, graph) ; }
+//    
+//    /** Write a dataset as TriG
+//     * @param out       OutputStream
+//     * @param dataset   Dataset to write 
+//     */
+//    public static void writeTrig(OutputStream out, Dataset dataset)
+//    { writeTrig(out, dataset.asDatasetGraph()) ; }
+//
+//    /** Write a dataset as TriG
+//     * @param out       OutputStream
+//     * @param dataset   Dataset to write 
+//     */
+//    public static void writeTrig(OutputStream out, DatasetGraph dataset)
+//    { createTrig().write(out, dataset) ; }
+//    
+//    /** Write a dataset as TriG, using a streaming writer
+//     * @param out       OutputStream
+//     * @param dataset   Dataset to write 
+//     */
+//    public static void writeTrigStreaming(OutputStream out, Dataset dataset)
+//    { writeTrigStreaming(out, dataset.asDatasetGraph()) ; }
+//
+//    /** Write a dataset as TriG, using a streaming writer
+//     * @param out       OutputStream
+//     * @param dataset   Dataset to write 
+//     */
+//    public static void writeTrigStreaming(OutputStream out, DatasetGraph dataset)
+//    { createTrigStreaming().write(out, dataset) ; }
+//    
+//    /** Write a dataset as NQuads
+//     * @param out       OutputStream
+//     * @param dataset   Dataset to write 
+//     */
+//    public static void writeNQuads(OutputStream out, Dataset dataset)
+//    { writeNQuads(out, dataset.asDatasetGraph()) ; }
+//    
+//    /** Write a dataset as NQuads
+//     * @param out       OutputStream
+//     * @param dataset   Dataset to write 
+//     */
+//    public static void writeNQuads(OutputStream out, DatasetGraph dataset)
+//    { createNQuads().write(out, dataset) ; }
+//    
+    // ---- Create writers
+
+    /** Create a Turtle writer */
+    public static WriterGraphRIOT createTurtle()            { return new TurtleWriter() ; }
+
+    /** Create a streaming Turtle writer */
+    public static WriterGraphRIOT createTurtleStreaming()   { return new TurtleWriterBlocks() ; }
+
+    /** Create a streaming Turtle outputing one triple per line using Turtle abbreviations */
+    public static WriterGraphRIOT createTurtleFlat()        { return new TurtleWriterFlat() ; }
+
+    /** Create an N-Triples writer */
+    public static WriterGraphRIOT createNTriples()          { return new NTriplesWriter() ; }
+
+    /** Create an RDF/XML writer which pretty-prints */
+    public static WriterGraphRIOT createRDFXMLAbbrev()      { return new RDFXMLAbbrevWriter() ; }
+
+    /** Create an RDF/XML writer which does not pretty-print */
+    public static WriterGraphRIOT createRDFXMLPlain()       { return new RDFXMLPlainWriter() ; }
+
+    /** Create an RDF/JSON writer */
+    public static WriterGraphRIOT createRDFJSON()           { return new RDFJSONWriter() ; }
+
+    /** Create a TriG writer */
+    public static WriterDatasetRIOT createTrig()            { return new TriGWriter() ; }
+
+    /** Create a TriG writer that streams */
+    public static WriterDatasetRIOT createTrigStreaming()   { return new TriGWriterBlocks() ; }
+
+    /** Create a TriG writer that writes one quad per line in Trig, using abbreviated forms */ 
+    public static WriterDatasetRIOT createTrigFlat()        { return new TriGWriterFlat() ; }
+
+    /** Create an NQuads writer */
+    public static WriterDatasetRIOT createNQuads()          { return new NQuadsWriter() ; }
+
+    public static WriterDatasetRIOT createRDFNULL()         { return NullWriter.factory.create(RDFFormat.RDFNULL) ; }           
 }
+

Added: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/WriterDatasetRIOT.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/WriterDatasetRIOT.java?rev=1452591&view=auto
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/WriterDatasetRIOT.java (added)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/WriterDatasetRIOT.java Mon Mar  4 23:22:53 2013
@@ -0,0 +1,65 @@
+/**
+ * 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.Writer ;
+
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.system.PrefixMap ;
+
+import com.hp.hpl.jena.sparql.core.DatasetGraph ;
+import com.hp.hpl.jena.sparql.util.Context ;
+
+/**
+ * A RIOT serializer for a language.
+ * This covers both graphs and datasets.
+ * A WriterRIOT is a one-time use object (they may accumulate state, e.g. pretty writers).
+ */
+public interface WriterDatasetRIOT
+{
+//    public void  write(OutputStream out, DatasetGraph datasetGraph) ;
+//    
+//    //public void  write(OutputStream out, DatasetGraph datasetGraph, PrefixMap prefixMap) ;
+//
+//    public void  write(OutputStream out, DatasetGraph datasetGraph, String baseURI) ;
+    
+    /**
+     * @param out           OutputStream
+     * @param datasetGraph  DatasetGraph to be written
+     * @param prefixMap     PrefixMap - maybe null (default should be to use the prefixmapping from the Graph)
+     * @param baseURI       base URI - may be null for "none"
+     * @param context       Context (see specific implementation for details) 
+     */
+    public void  write(OutputStream out, DatasetGraph datasetGraph, PrefixMap prefixMap, String baseURI, Context context) ;
+
+//    /** Use of Writer is discouraged - let the serializer manage character sets in accordance with the format */
+//    public void  write(Writer out, DatasetGraph datasetGraph) ;
+    
+    /** Use of Writer is discouraged - let the serializer manage character sets in accordance with the format
+     * @param out           Writer
+     * @param datasetGraph  DatasetGraph to be written
+     * @param prefixMap     PrefixMap - maybe null (default should be to use the prefixmapping from the Graph)
+     * @param baseURI       base URI - may be null for "none"
+     * @param context       Context (see specific implementation for details) 
+     */
+    public void  write(Writer out, DatasetGraph datasetGraph, PrefixMap prefixMap, String baseURI, Context context) ;
+    
+    public Lang  getLang() ;
+}

Added: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/WriterDatasetRIOTFactory.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/WriterDatasetRIOTFactory.java?rev=1452591&view=auto
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/WriterDatasetRIOTFactory.java (added)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/WriterDatasetRIOTFactory.java Mon Mar  4 23:22:53 2013
@@ -0,0 +1,25 @@
+/**
+ * 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;
+
+/** Factory for creating dataset writers */ 
+public interface WriterDatasetRIOTFactory
+{
+    public WriterDatasetRIOT create(RDFFormat syntaxForm) ;
+}

Added: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/WriterGraphRIOT.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/WriterGraphRIOT.java?rev=1452591&view=auto
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/WriterGraphRIOT.java (added)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/WriterGraphRIOT.java Mon Mar  4 23:22:53 2013
@@ -0,0 +1,58 @@
+/**
+ * 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.Writer ;
+
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.system.PrefixMap ;
+import org.apache.jena.riot.writer.WriterGraphRIOTBase ;
+
+import com.hp.hpl.jena.graph.Graph ;
+import com.hp.hpl.jena.sparql.util.Context ;
+
+/**
+ * A RIOT serializer for a language.
+ * This covers both graphs and datasets.
+ * A WriterRIOT is a one-time use object (they may accumulate state, e.g. pretty writers).
+ * @see WriterGraphRIOTBase
+ */
+public interface WriterGraphRIOT
+{
+    /**
+     * @param out           OutputStream
+     * @param graph         Graph to be written
+     * @param prefixMap     PrefixMap - maybe null (default should be to use the prefixmapping from the Graph)
+     * @param baseURI       base URI - may be null for "none"
+     * @param context       Context (see specific implementation for details) 
+     */
+    public void  write(OutputStream out, Graph graph, PrefixMap prefixMap, String baseURI, Context context) ;
+
+    /** Use of Writer is discouraged - let the serializer manage character sets in accordance with the format
+     * @param out           Writer
+     * @param graph         Graph to be written
+     * @param prefixMap     PrefixMap - maybe null (default should be to use the prefixmapping from the Graph)
+     * @param baseURI       base URI - may be null for "none"
+     * @param context       Context (see specific implementation for details) 
+     */
+    public void  write(Writer out, Graph graph, PrefixMap prefixMap, String baseURI, Context context) ;
+    
+    public Lang  getLang() ;
+}

Added: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/WriterGraphRIOTFactory.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/WriterGraphRIOTFactory.java?rev=1452591&view=auto
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/WriterGraphRIOTFactory.java (added)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/WriterGraphRIOTFactory.java Mon Mar  4 23:22:53 2013
@@ -0,0 +1,25 @@
+/**
+ * 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;
+
+/** Factory for creating graph writers */ 
+public interface WriterGraphRIOTFactory
+{
+    public WriterGraphRIOT create(RDFFormat syntaxForm) ;
+}

Added: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/WriterRIOT.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/WriterRIOT.java?rev=1452591&view=auto
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/WriterRIOT.java (added)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/WriterRIOT.java Mon Mar  4 23:22:53 2013
@@ -0,0 +1,57 @@
+/**
+ * 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.Writer ;
+
+import org.apache.jena.riot.system.PrefixMap ;
+
+import com.hp.hpl.jena.sparql.util.Context ;
+
+/*public*/ interface WriterRIOT
+{
+    /**
+     * @param out           OutputStream
+     */
+    public void write(OutputStream out) ;
+
+    /**
+     * @param out           OutputStream
+     * @param baseURI       base URI - may be null for "none"
+     */
+
+    public void write(OutputStream out, String baseURI) ;
+    /**
+     * @param out           OutputStream
+     * @param prefixMap     PrefixMap - maybe null (default should be to use the prefixmapping from the Graph)
+     * @param baseURI       base URI - may be null for "none"
+     * @param context       Context (see specific implementation for details) 
+     */
+    public void write(OutputStream out, PrefixMap prefixMap, String baseURI, Context context) ;
+
+    /** Use of Writer is discouraged - let the serializer manage character sets in accordance with the format
+     * @param out           Writer
+     * @param prefixMap     PrefixMap - maybe null (default should be to use the prefixmapping from the Graph)
+     * @param baseURI       base URI - may be null for "none"
+     * @param context       Context (see specific implementation for details) 
+     */
+    public void  write(Writer out, PrefixMap prefixMap, String baseURI, Context context) ;
+}
+

Added: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/adapters/AdapterRDFWriter.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/adapters/AdapterRDFWriter.java?rev=1452591&view=auto
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/adapters/AdapterRDFWriter.java (added)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/adapters/AdapterRDFWriter.java Mon Mar  4 23:22:53 2013
@@ -0,0 +1,55 @@
+/**
+ * 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.adapters;
+
+import java.io.OutputStream ;
+import java.io.Writer ;
+
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.system.PrefixMap ;
+import org.apache.jena.riot.writer.WriterGraphRIOTBase ;
+
+import com.hp.hpl.jena.graph.Graph ;
+import com.hp.hpl.jena.rdf.model.ModelFactory ;
+import com.hp.hpl.jena.rdf.model.RDFWriter ;
+import com.hp.hpl.jena.sparql.util.Context ;
+
+/** Wrapper for using old-style Jena RDFWriters in RIOT. */
+
+public abstract class AdapterRDFWriter extends WriterGraphRIOTBase
+{
+    protected abstract RDFWriter create() ;
+    
+    @Override public abstract Lang getLang() ;
+
+    @Override
+    public void write(Writer out, Graph graph, PrefixMap prefixMap, String baseURI, Context context)
+    {
+        RDFWriter w = create() ;
+        w.write(ModelFactory.createModelForGraph(graph), out, baseURI) ;
+    }
+
+    @Override
+    public void write(OutputStream out, Graph graph, PrefixMap prefixMap, String baseURI, Context context)
+    {
+        RDFWriter w = create() ;
+        w.write(ModelFactory.createModelForGraph(graph), out, baseURI) ;
+    }
+}
+

Added: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/adapters/RDFWriterRIOT.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/adapters/RDFWriterRIOT.java?rev=1452591&view=auto
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/adapters/RDFWriterRIOT.java (added)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/adapters/RDFWriterRIOT.java Mon Mar  4 23:22:53 2013
@@ -0,0 +1,88 @@
+/**
+ * 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.adapters;
+
+import static org.apache.jena.riot.system.RiotWriterLib.prefixMap ;
+
+import java.io.OutputStream ;
+import java.io.Writer ;
+
+import org.apache.jena.riot.* ;
+import org.apache.jena.riot.system.IO_Jena2 ;
+
+import com.hp.hpl.jena.graph.Graph ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.RDFErrorHandler ;
+import com.hp.hpl.jena.rdf.model.RDFWriter ;
+import com.hp.hpl.jena.sparql.util.Context ;
+
+/** Adapter from RIOT to old style Jena RDFWriter. */
+public class RDFWriterRIOT implements RDFWriter 
+{
+    private final String jenaName ; 
+    private Context context = new Context() ;
+    
+    public RDFWriterRIOT(String jenaName)
+    { 
+        this.jenaName = jenaName ;
+    }
+    
+    //Initial late to avoid confusing exceptions during newInstance. 
+    private WriterGraphRIOT writer()
+    {
+        RDFFormat format = IO_Jena2.getFormatForJenaWriter(jenaName) ;
+        if ( format != null )
+            return RDFWriterMgr.createGraphWriter(format) ;
+        // Try lang instead.
+        Lang lang = RDFLanguages.nameToLang(jenaName) ;
+        if ( lang != null )
+            return RDFWriterMgr.createGraphWriter(lang) ;
+        throw new RiotException("No graph writer for '"+jenaName+"'") ;
+    }
+    
+    @Override
+    public void write(Model model, Writer out, String base)
+    {
+        if (  base != null && base.equals("") )
+            base = null ;
+        Graph graph = model.getGraph() ;
+        writer().write(out, graph, prefixMap(graph), base, context) ;
+    }
+
+    @Override
+    public void write(Model model, OutputStream out, String base)
+    {
+        if ( base != null && base.equals("") )
+            base = null ;
+        Graph graph = model.getGraph() ;
+        writer().write(out, graph, prefixMap(graph), base, context) ;
+    }
+
+    @Override
+    public Object setProperty(String propName, Object propValue)
+    {
+        return null ;
+    }
+
+    @Override
+    public RDFErrorHandler setErrorHandler(RDFErrorHandler errHandler)
+    {
+        return null ;
+    }
+}

Added: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/other/BatchedStreamRDF.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/other/BatchedStreamRDF.java?rev=1452591&view=auto
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/other/BatchedStreamRDF.java (added)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/other/BatchedStreamRDF.java Mon Mar  4 23:22:53 2013
@@ -0,0 +1,165 @@
+/**
+ * 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.other;
+
+import java.util.ArrayList ;
+import java.util.List ;
+
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.atlas.lib.Tuple ;
+import org.apache.jena.riot.system.StreamRDF ;
+
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.graph.Triple ;
+import com.hp.hpl.jena.sparql.core.Quad ;
+
+/** Batch a stream into triples and/or quads.
+ *  Triples are batched on subject
+ *  Quads are batched on (graph, subject). 
+ *  
+ */
+public class BatchedStreamRDF implements StreamRDF
+{
+    // Extract the state machine ?
+    private final StreamRDFBatchHandler batchProc ;
+    private Node currentSubject         = null ;
+    private Node currentGraph           = null ;
+    private List<Triple> batchTriples   = null ;
+    private List<Quad>   batchQuads     = null ;
+    
+    public BatchedStreamRDF(StreamRDFBatchHandler batchProc)
+    {
+        this.batchProc = batchProc ;
+    }
+    
+    @Override
+    public final void start()
+    {
+        currentSubject  = null ;
+        currentGraph    = null ;
+        batchTriples    = null ;
+        batchQuads      = null ;
+        batchProc.start() ;
+    }
+    
+    // ---- Triples 
+    @Override
+    public void triple(Triple triple)
+    {
+        Node s = triple.getSubject() ;
+//        Node p = triple.getPredicate() ;
+//        Node o = triple.getObject() ;
+
+        if ( ! Lib.equal(s, currentSubject) )
+        {
+            if ( currentSubject != null )
+                finishBatchTriple(currentSubject) ;
+            startBatchTriple(s) ;
+            
+            currentGraph = null ;
+            currentSubject = s ;
+        }
+        
+        processTriple(triple) ;
+    }
+
+    private void startBatchTriple(Node subject)
+    {
+        batchTriples = new ArrayList<Triple>() ;
+    }
+    
+    private void finishBatchTriple(Node subject)
+    {
+        if ( batchTriples != null && batchTriples.size() > 0 )
+            batchProc.batchTriples(currentSubject, batchTriples) ;
+    }
+
+    private void processTriple(Triple triple)
+    {
+        batchTriples.add(triple) ;
+    }
+
+    // ---- Quads 
+    @Override
+    public void quad(Quad quad)
+    {
+        if ( false )
+        {
+            // Merge to a triple stream.
+            triple(quad.asTriple()) ;
+            return ;
+        }
+        
+        Node g = quad.getGraph() ;
+        Node s = quad.getSubject() ;
+        
+//            Node p = triple.getPredicate() ;
+//            Node o = triple.getObject() ;
+        
+        if ( ! Lib.equal(g, currentGraph) || ! Lib.equal(s,  currentSubject) )
+        {
+            if ( currentSubject != null )
+                finishBatchQuad(currentGraph, currentSubject) ;
+            startBatchQuad(g, s) ;
+            currentGraph = g ;
+            currentSubject = s ;
+        }
+        processQuad(quad) ;
+    }
+
+    private void startBatchQuad(Node graph, Node subject)
+    {
+        batchQuads = new ArrayList<Quad>() ;
+    }
+    
+    private void finishBatchQuad(Node graph, Node subject)
+    {
+        if ( batchQuads != null && batchQuads.size() > 0 )
+            batchProc.batchQuads(currentGraph, currentSubject, batchQuads) ;
+    }
+
+    private void processQuad(Quad Quad)
+    {
+        batchQuads.add(Quad) ;
+    }
+    
+    private void flush()
+    {
+        finishBatchTriple(currentSubject) ;
+        finishBatchQuad(currentGraph, currentSubject) ;
+    }
+    
+    @Override
+    public final void finish()
+    {
+        flush() ;
+        batchProc.finish() ;
+
+    }
+
+    @Override
+    public void tuple(Tuple<Node> tuple)            { throw new UnsupportedOperationException("Tuples not supported") ; }
+
+    @Override
+    public void base(String base)                   { batchProc.base(base) ; }
+
+    @Override
+    public void prefix(String prefix, String iri)   { batchProc.prefix(prefix, iri) ; }
+}
+

Added: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/other/GLib.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/other/GLib.java?rev=1452591&view=auto
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/other/GLib.java (added)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/other/GLib.java Mon Mar  4 23:22:53 2013
@@ -0,0 +1,131 @@
+/**
+ * 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.other;
+
+import java.util.Iterator ;
+
+import org.apache.jena.atlas.iterator.Iter ;
+import org.apache.jena.atlas.iterator.Transform ;
+
+import com.hp.hpl.jena.graph.Graph ;
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.graph.Triple ;
+import com.hp.hpl.jena.sparql.core.Quad ;
+import com.hp.hpl.jena.util.iterator.ExtendedIterator ;
+
+/** A collection of Graph/Triple/Node related functions */
+public class GLib
+{
+    /** Convert null to Node.ANY */
+    public static Node nullAsAny(Node x) { return nullAsDft(x, Node.ANY) ; }
+    
+    /** Convert null to some default Node */
+    public static Node nullAsDft(Node x, Node dft) { return x==null ? dft : x ; }
+    
+    // DISTINCT means these are space using.
+    /** List the subjects in a graph (no duplicates) */
+    public static Iterator<Node> listSubjects(Graph graph)
+    {
+        ExtendedIterator<Triple> iter = graph.find(Node.ANY, Node.ANY, Node.ANY) ;
+        return Iter.iter(iter).map(projectTripeSubject).distinct() ;
+    }
+
+    /** List the predicates in a graph (no duplicates) */
+    public static Iterator<Node> listPredicates(Graph graph)
+    {
+        ExtendedIterator<Triple> iter = graph.find(Node.ANY, Node.ANY, Node.ANY) ;
+        return Iter.iter(iter).map(projectTripePredicate).distinct() ;
+    }
+    
+    /** List the objects in a graph (no duplicates) */
+    public static Iterator<Node> listObjects(Graph graph)
+    {
+        ExtendedIterator<Triple> iter = graph.find(Node.ANY, Node.ANY, Node.ANY) ;
+        return Iter.iter(iter).map(projectTripeObject).distinct() ;
+    }
+    
+    private static Transform<Quad, Triple> transformQuad2Triple = new Transform<Quad, Triple> () {
+        @Override
+        public Triple convert(Quad quad)    { return quad.asTriple() ; }
+    } ;
+
+    /** Project quads to triples */
+    public static Iter<Triple> quads2triples(Iterator<Quad> iter)
+    {
+        return Iter.iter(iter).map(transformQuad2Triple) ;
+    }
+
+    /** Project quad to graphname */
+    public static Iterator<Node> quad2graphName(Iterator<Quad> iter)
+    { return Iter.map(iter, projectQuadGraphName) ; }
+    
+    /** Project quad to graphname */
+    public static Iterator<Node> quad2subject(Iterator<Quad> iter)
+    { return Iter.map(iter, projectQuadSubject) ; }
+    
+    /** Project quad to predicate */
+    public static Iterator<Node> quad2predicate(Iterator<Quad> iter)
+    { return Iter.map(iter, projectQuadPredicate) ; }
+    
+    /** Project quad to object */
+    public static Iterator<Node> quad2object(Iterator<Quad> iter)
+    { return Iter.map(iter, projectQuadObject) ; }
+    
+    /** Project triple to subject */ 
+    public static Iterator<Node> triple2subject(Iterator<Triple> iter)
+    { return Iter.map(iter, projectTripeSubject) ; }
+    
+    /** Project triple to predicate */ 
+    public static Iterator<Node> triple2predicate(Iterator<Triple> iter)
+    { return Iter.map(iter, projectTripePredicate) ; }
+    
+    /** Project triple to object */ 
+    public static Iterator<Node> triple2object(Iterator<Triple> iter)
+    { return Iter.map(iter, projectTripeObject) ; }
+
+    /** Transform quad to graphname */
+    public static Transform<Quad, Node> projectQuadGraphName = new Transform<Quad, Node>() {
+        @Override  public Node convert(Quad quad) { return quad.getGraph() ; }
+    } ;
+    /** Transform quad to subject */
+    public static Transform<Quad, Node> projectQuadSubject = new Transform<Quad, Node>() {
+        @Override  public Node convert(Quad quad) { return quad.getSubject() ; }
+    } ;
+    /** Transform quad to predicate */
+    public static Transform<Quad, Node> projectQuadPredicate = new Transform<Quad, Node>() {
+        @Override public Node convert(Quad quad) { return quad.getPredicate() ; }
+    } ;
+    /** Transform quad to object */
+    public static Transform<Quad, Node> projectQuadObject = new Transform<Quad, Node>() {
+        @Override public Node convert(Quad quad) { return quad.getObject() ; }
+    } ;
+    /** Transform triple to subject */ 
+    public static Transform<Triple, Node> projectTripeSubject   = new Transform<Triple, Node>() {
+        @Override public Node convert(Triple triple) { return triple.getSubject() ; }
+    } ;
+    /** Transform triple to predicate */ 
+    public static Transform<Triple, Node> projectTripePredicate = new Transform<Triple, Node>() {
+        @Override public Node convert(Triple triple) { return triple.getPredicate() ; }
+    } ;
+    /** Transform triple to object */ 
+    public static Transform<Triple, Node> projectTripeObject    = new Transform<Triple, Node>() {
+        @Override public Node convert(Triple triple) { return triple.getObject() ; }
+    } ;
+}
+

Added: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/other/StreamRDFBatchHandler.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/other/StreamRDFBatchHandler.java?rev=1452591&view=auto
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/other/StreamRDFBatchHandler.java (added)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/other/StreamRDFBatchHandler.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 org.apache.jena.riot.other;
+
+import java.util.List ;
+
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.graph.Triple ;
+import com.hp.hpl.jena.sparql.core.Quad ;
+
+public interface StreamRDFBatchHandler
+{
+    /** Start */
+    public void start() ;
+    
+    /** Triple emitted 
+     * @param currentSubject */
+    public void batchTriples(Node currentSubject , List<Triple> triples) ;
+
+    /** Quad emitted 
+     * @param currentSubject 
+     * @param currentGraph 
+     * @param quads
+     * */
+    public void batchQuads(Node currentGraph , Node currentSubject , List<Quad> quads) ;
+
+    /** base declaration seen */
+    public void base(String base) ;
+
+    /** prefix declaration seen */
+    public void prefix(String prefix, String iri) ;
+
+    /** Finish parsing */
+    public void finish() ;
+}
+

Modified: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/EscapeStr.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/EscapeStr.java?rev=1452591&r1=1452590&r2=1452591&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/EscapeStr.java (original)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/EscapeStr.java Mon Mar  4 23:22:53 2013
@@ -18,15 +18,11 @@
 
 package org.apache.jena.riot.out;
 
-import java.io.IOException ;
-import java.io.StringWriter ;
-import java.io.Writer ;
+import org.apache.jena.atlas.io.IndentedLineBuffer ;
+import org.apache.jena.atlas.io.WriterI ;
 
 import com.hp.hpl.jena.sparql.lang.ParserBase ;
 
-import org.apache.jena.atlas.io.IO ;
-import org.apache.jena.atlas.io.OutputUtils ;
-
 public class EscapeStr
 {
     // Tests: TestOutput
@@ -34,93 +30,81 @@ public class EscapeStr
     private final boolean ascii ;
 
     public EscapeStr(boolean asciiOnly) { this.ascii = asciiOnly ; }
-    
-    public void writeURI(Writer w, String s)
+
+    public void writeURI(WriterI w, String s)
     {
-        try
-        {
-            if ( ascii )
-                stringEsc(w, s, true, ascii) ;
-            else
-                // It's a URI - assume legal.
-                w.write(s) ;
-        } catch (IOException e) { IO.exception(e) ; }
+        if ( ascii )
+            stringEsc(w, s, true, ascii) ;
+        else
+            // It's a URI - assume legal.
+            w.print(s) ;
     }
-    
-    public void writeStr(Writer w, String s) 
+
+    public void writeStr(WriterI w, String s) 
     {
-        try
-        {
-            stringEsc(w, s, true, ascii) ;
-        } catch (IOException e) { IO.exception(e) ; }
+        stringEsc(w, s, true, ascii) ;
     }
-    
-    public void writeStrMultiLine(Writer w, String s) 
+
+    public void writeStrMultiLine(WriterI w, String s) 
     {
         // N-Triples does not have """
-        try
-        {
-            stringEsc(w, s, false, ascii) ;
-        } catch (IOException e) { IO.exception(e) ; }
+        stringEsc(w, s, false, ascii) ;
     }
-    
+
     // Utility
     /*
      * Escape characters in a string according to Turtle rules. 
      */
     public static String stringEsc(String s)
     { return stringEsc(s, true, false) ; }
-    
+
     private static String stringEsc(String s, boolean singleLineString, boolean asciiOnly)
     {
-        try
-        {
-            Writer sb = new StringWriter() ;
-            stringEsc(sb, s, singleLineString, asciiOnly) ;
-            return sb.toString() ;
-        } catch (IOException e) { IO.exception(e) ; return null ; }
+        IndentedLineBuffer sb = new IndentedLineBuffer() ;
+        stringEsc(sb, s, singleLineString, asciiOnly) ;
+        return sb.toString() ;
     }
-    
-    public static void stringEsc(Writer out, String s, boolean singleLineString, boolean asciiOnly) throws IOException
+
+    public static void stringEsc(WriterI out, String s, boolean singleLineString, boolean asciiOnly)
     {
         int len = s.length() ;
         for (int i = 0; i < len; i++) {
             char c = s.charAt(i);
-            
+
             // \\ Escape always possible.
             if (c == '\\') 
             {
-                out.write('\\') ;
-                out.write(c) ;
+                out.print('\\') ;
+                out.print(c) ;
                 continue ;
             }
             if ( singleLineString )
             {
-                if ( c == '"' )         { out.write("\\\""); continue ; }
-                else if (c == '\n')     { out.write("\\n");  continue ; }
-                else if (c == '\t')     { out.write("\\t");  continue ; }
-                else if (c == '\r')     { out.write("\\r");  continue ; }
-                else if (c == '\f')     { out.write("\\f");  continue ; }
+                if ( c == '"' )         { out.print("\\\""); continue ; }
+                else if (c == '\n')     { out.print("\\n");  continue ; }
+                else if (c == '\t')     { out.print("\\t");  continue ; }
+                else if (c == '\r')     { out.print("\\r");  continue ; }
+                else if (c == '\f')     { out.print("\\f");  continue ; }
             }
             // Not \-style esacpe. 
             if ( c >= 32 && c < 127 )
-                out.write(c);
+                out.print(c);
             else if ( !asciiOnly )
-                out.write(c);
+                out.print(c);
             else
             {
                 // Outside the charset range.
                 // Does not cover beyond 16 bits codepoints directly
                 // (i.e. \U escapes) but Java keeps these as surrogate
                 // pairs and will print as characters
-                out.write( "\\u") ;
+                out.print( "\\u") ;
                 OutputUtils.printHex(out, c, 4) ;
             }
         }
     }
-    
+
     // Utilities to remove escapes
-    
+
     public static String unescapeStr(String s)
     { return unescape(s, '\\') ; }
     

Modified: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/NodeFmtLib.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/NodeFmtLib.java?rev=1452591&r1=1452590&r2=1452591&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/NodeFmtLib.java (original)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/NodeFmtLib.java Mon Mar  4 23:22:53 2013
@@ -18,25 +18,20 @@
 
 package org.apache.jena.riot.out;
 
-import java.io.StringWriter ;
-import java.io.Writer ;
 import java.net.MalformedURLException ;
 import java.util.Map ;
 
-
-import com.hp.hpl.jena.graph.Node ;
-import com.hp.hpl.jena.graph.Triple ;
-
+import org.apache.jena.atlas.io.IndentedLineBuffer ;
+import org.apache.jena.atlas.io.IndentedWriter ;
 import org.apache.jena.atlas.lib.Bytes ;
 import org.apache.jena.atlas.lib.Chars ;
 import org.apache.jena.iri.IRI ;
 import org.apache.jena.iri.IRIFactory ;
 import org.apache.jena.iri.IRIRelativize ;
-import org.apache.jena.riot.system.PrefixMap;
-import org.apache.jena.riot.system.PrefixMapFactory;
-import org.apache.jena.riot.system.Prologue ;
-import org.apache.jena.riot.system.RiotChars ;
+import org.apache.jena.riot.system.* ;
 
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.graph.Triple ;
 import com.hp.hpl.jena.shared.PrefixMapping ;
 import com.hp.hpl.jena.sparql.ARQConstants ;
 import com.hp.hpl.jena.sparql.core.Quad ;
@@ -47,7 +42,7 @@ public class NodeFmtLib
     // See OutputLangUtils.
     // See and use EscapeStr
     
-    static PrefixMap dftPrefixMap = PrefixMapFactory.createForOutput() ;
+    static PrefixMap dftPrefixMap = PrefixMapFactory.create() ;
     static {
         PrefixMapping pm = ARQConstants.getGlobalPrefixMap() ;
         Map<String, String> map = pm.getNsPrefixMap() ;
@@ -69,13 +64,15 @@ public class NodeFmtLib
     // Worker
     public static String strNodes(Node ... nodes)
     {
-        StringWriter sw = new StringWriter() ;
+        IndentedLineBuffer sw = new IndentedLineBuffer() ;
         boolean first = true ;
         for ( Node n : nodes ) 
         {
             if ( ! first )
+            {
                 sw.append(" ") ;
-            first = false ;
+                first = false ;
+            }
             str(sw, n) ;
         }
         return sw.toString() ; 
@@ -83,7 +80,7 @@ public class NodeFmtLib
 
     public static String str(Node n)
     {
-        StringWriter sw = new StringWriter() ;
+        IndentedLineBuffer sw = new IndentedLineBuffer() ;
         str(sw, n) ;
         return sw.toString() ; 
     }
@@ -92,14 +89,14 @@ public class NodeFmtLib
 
     //public static String displayStr(Node n) { return serialize(n) ; }
 
-    public static void str(Writer w, Node n)
+    public static void str(IndentedWriter w, Node n)
     { serialize(w, n, null, null) ; }
 
-    public static void serialize(Writer w, Node n, Prologue prologue)
+    public static void serialize(IndentedWriter w, Node n, Prologue prologue)
     { serialize(w, n, prologue.getBaseURI(), prologue.getPrefixMap()) ; }
 
     
-    public static void serialize(Writer w, Node n, String base, PrefixMap prefixMap)
+    public static void serialize(IndentedWriter w, Node n, String base, PrefixMap prefixMap)
     {
         if ( prefixMap == null )
             prefixMap = dftPrefixMap ;

Modified: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/NodeFormatter.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/NodeFormatter.java?rev=1452591&r1=1452590&r2=1452591&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/NodeFormatter.java (original)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/NodeFormatter.java Mon Mar  4 23:22:53 2013
@@ -18,35 +18,37 @@
 
 package org.apache.jena.riot.out;
 
-import java.io.Writer ;
+
+
+import org.apache.jena.atlas.io.WriterI ;
 
 import com.hp.hpl.jena.graph.Node ;
 
 public interface NodeFormatter
 {
-    public void format(Writer w, Node n) ;
+    public void format(WriterI w, Node n) ;
 
     /** Node is guaranteed to be a URI node */
-    public void formatURI(Writer w, Node n) ;
-    public void formatURI(Writer w, String uriStr) ;
+    public void formatURI(WriterI w, Node n) ;
+    public void formatURI(WriterI w, String uriStr) ;
     
-    public void formatVar(Writer w, Node n) ;
-    public void formatVar(Writer w, String name) ;
+    public void formatVar(WriterI w, Node n) ;
+    public void formatVar(WriterI w, String name) ;
     
     /** Node is guaranteed to be a blank node */
-    public void formatBNode(Writer w, Node n) ;
-    public void formatBNode(Writer w, String label) ;
+    public void formatBNode(WriterI w, Node n) ;
+    public void formatBNode(WriterI w, String label) ;
     
     /** Node is guaranteed to be a literal */
-    public void formatLiteral(Writer w, Node n) ;
+    public void formatLiteral(WriterI w, Node n) ;
     
     /** Plain string / xsd:string (RDF 1.1) */
-    public void formatLitString(Writer w, String lex) ;
+    public void formatLitString(WriterI w, String lex) ;
     
     /** String with language tag */
-    public void formatLitLang(Writer w, String lex, String langTag) ;
+    public void formatLitLang(WriterI w, String lex, String langTag) ;
 
     /** Literal with datatype, not a simple literal, not an xsd:string (RDF 1.1), no language tag. */
-    public void formatLitDT(Writer w, String lex, String datatypeURI) ;
+    public void formatLitDT(WriterI w, String lex, String datatypeURI) ;
     
 }

Modified: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/NodeFormatterBase.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/NodeFormatterBase.java?rev=1452591&r1=1452590&r2=1452591&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/NodeFormatterBase.java (original)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/NodeFormatterBase.java Mon Mar  4 23:22:53 2013
@@ -18,10 +18,7 @@
 
 package org.apache.jena.riot.out;
 
-import java.io.IOException ;
-import java.io.Writer ;
-
-import org.apache.jena.atlas.io.IO ;
+import org.apache.jena.atlas.io.WriterI ;
 
 import com.hp.hpl.jena.graph.Node ;
 import com.hp.hpl.jena.sparql.ARQInternalErrorException ;
@@ -32,7 +29,7 @@ import com.hp.hpl.jena.sparql.ARQInterna
 public abstract class NodeFormatterBase implements NodeFormatter
 {
     @Override
-    public void format(Writer w, Node n)
+    public void format(WriterI w, Node n)
     {
         if ( n.isBlank() )
             formatBNode(w, n) ;
@@ -43,20 +40,19 @@ public abstract class NodeFormatterBase 
         else if ( n.isVariable() )
             formatVar(w, n) ;
         else if ( Node.ANY.equals(n) )
-            try { w.write("ANY") ; }
-            catch (IOException ex) { IO.exception(ex) ; }
+            w.print("ANY") ;
         else
             throw new ARQInternalErrorException("Unknow node type: "+n) ;
     }
     
     @Override
-    public void formatURI(Writer w, Node n)         { formatURI(w, n.getURI()) ; }
+    public void formatURI(WriterI w, Node n)         { formatURI(w, n.getURI()) ; }
 
     @Override
-    public void formatBNode(Writer w, Node n)       { formatBNode(w, n.getBlankNodeLabel()) ; }
+    public void formatBNode(WriterI w, Node n)       { formatBNode(w, n.getBlankNodeLabel()) ; }
 
     @Override
-    public void formatLiteral(Writer w, Node n)
+    public void formatLiteral(WriterI w, Node n)
     {
         String dt = n.getLiteralDatatypeURI() ;
         String lang = n.getLiteralLanguage() ;
@@ -74,5 +70,5 @@ public abstract class NodeFormatterBase 
     }
 
     @Override
-    public void formatVar(Writer w, Node n)         { formatVar(w, n.getName()) ; }
+    public void formatVar(WriterI w, Node n)         { formatVar(w, n.getName()) ; }
 }

Modified: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/NodeFormatterNT.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/NodeFormatterNT.java?rev=1452591&r1=1452590&r2=1452591&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/NodeFormatterNT.java (original)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/NodeFormatterNT.java Mon Mar  4 23:22:53 2013
@@ -18,10 +18,8 @@
 
 package org.apache.jena.riot.out;
 
-import java.io.IOException ;
-import java.io.Writer ;
 
-import org.apache.jena.atlas.io.IO ;
+import org.apache.jena.atlas.io.WriterI ;
 
 public class NodeFormatterNT extends NodeFormatterBase
 {
@@ -29,72 +27,60 @@ public class NodeFormatterNT extends Nod
     // Turtles extends this class to intercept forms it can do better.
 
     private final EscapeStr escapeProc ; 
-    
+
     public NodeFormatterNT() { this(true) ; }
-    
+
     protected NodeFormatterNT(boolean asciiOnly) { escapeProc = new EscapeStr(asciiOnly) ;}
-    
+
     @Override
-    public void formatURI(Writer w, String uriStr)
+    public void formatURI(WriterI w, String uriStr)
     {
-        try {
-            w.write('<') ;
-            w.write(uriStr) ;
-            w.write('>') ;
-        } catch (IOException ex) { IO.exception(ex) ; } 
+        w.print('<') ;
+        w.print(uriStr) ;
+        w.print('>') ;
     }
 
     @Override
-    public void formatVar(Writer w, String name)
+    public void formatVar(WriterI w, String name)
     {
-        try {
-            w.write('?') ;
-            w.write(name) ;
-        } catch (IOException ex) { IO.exception(ex) ; }
+        w.print('?') ;
+        w.print(name) ;
     }
 
     @Override
-    public void formatBNode(Writer w, String label)
+    public void formatBNode(WriterI w, String label)
     {
-        try {
-            w.write("_:") ;
-            String lab = NodeFmtLib.encodeBNodeLabel(label) ;
-            w.write(lab) ;
-        } catch (IOException ex) { IO.exception(ex) ; }
+        w.print("_:") ;
+        String lab = NodeFmtLib.encodeBNodeLabel(label) ;
+        w.print(lab) ;
     }
 
     @Override
-    public void formatLitString(Writer w, String lex)
+    public void formatLitString(WriterI w, String lex)
     {
-        try {
-            writeEscaped(w, lex) ;
-        } catch (IOException ex) { IO.exception(ex) ; }
+        writeEscaped(w, lex) ;
     }
 
-    private void writeEscaped(Writer w, String lex) throws IOException
+    private void writeEscaped(WriterI w, String lex)
     {
-        w.write('"') ;
+        w.print('"') ;
         escapeProc.writeStr(w, lex) ;
-        w.write('"') ;
+        w.print('"') ;
     }
 
     @Override
-    public void formatLitLang(Writer w, String lex, String langTag)
+    public void formatLitLang(WriterI w, String lex, String langTag)
     {
-        try {
-            writeEscaped(w, lex) ;
-            w.write('@') ;
-            w.write(langTag) ;
-        } catch (IOException ex) { IO.exception(ex) ; }
+        writeEscaped(w, lex) ;
+        w.print('@') ;
+        w.print(langTag) ;
     }
 
     @Override
-    public void formatLitDT(Writer w, String lex, String datatypeURI)
+    public void formatLitDT(WriterI w, String lex, String datatypeURI)
     {
-        try {
-            writeEscaped(w, lex) ;
-            w.write("^^") ;
-            formatURI(w, datatypeURI) ;
-        } catch (IOException ex) { IO.exception(ex) ; }
+        writeEscaped(w, lex) ;
+        w.print("^^") ;
+        formatURI(w, datatypeURI) ;
     }
 }

Modified: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/NodeFormatterTTL.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/NodeFormatterTTL.java?rev=1452591&r1=1452590&r2=1452591&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/NodeFormatterTTL.java (original)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/NodeFormatterTTL.java Mon Mar  4 23:22:53 2013
@@ -18,71 +18,76 @@
 
 package org.apache.jena.riot.out;
 
-import java.io.IOException ;
-import java.io.Writer ;
 import java.net.MalformedURLException ;
 
-
-import com.hp.hpl.jena.datatypes.xsd.XSDDatatype ;
-
-import org.apache.jena.atlas.io.IO ;
+import org.apache.jena.atlas.io.WriterI ;
 import org.apache.jena.atlas.lib.Pair ;
 import org.apache.jena.iri.IRI ;
 import org.apache.jena.iri.IRIFactory ;
 import org.apache.jena.iri.IRIRelativize ;
-import org.apache.jena.riot.system.PrefixMap;
-import org.apache.jena.riot.system.PrefixMapFactory;
+import org.apache.jena.riot.out.NodeToLabel ;
+import org.apache.jena.riot.system.PrefixMap ;
+import org.apache.jena.riot.system.PrefixMapFactory ;
 import org.apache.jena.riot.system.RiotChars ;
 
+import com.hp.hpl.jena.datatypes.xsd.XSDDatatype ;
+import com.hp.hpl.jena.graph.Node ;
+
 public class NodeFormatterTTL extends NodeFormatterNT
 {
-    private final NodeToLabel nodeToLabel = NodeToLabel.createBNodeByLabelEncoded() ;
+    private final NodeToLabel nodeToLabel ;
     private final PrefixMap prefixMap ;
     private final String baseIRI ; 
     
-   public NodeFormatterTTL(String baseIRI , PrefixMap prefixMap) //OutputPolicy outputPolicy)
+    // Replace with a single "OutputPolicy"
+    public NodeFormatterTTL(String baseIRI , PrefixMap prefixMap) //OutputPolicy outputPolicy)
+    {
+        this(baseIRI, prefixMap, NodeToLabel.createBNodeByLabelEncoded()) ;
+    }
+    
+   public NodeFormatterTTL(String baseIRI , PrefixMap prefixMap, NodeToLabel nodeToLabel)
    {
        super(false) ;
+       this.nodeToLabel = nodeToLabel ;
        if ( prefixMap == null )
-           prefixMap = PrefixMapFactory.createForOutput() ;
+           prefixMap = PrefixMapFactory.create() ;
        this.prefixMap = prefixMap ;
        this.baseIRI = baseIRI ;
    }
     
     @Override
-    public void formatURI(Writer w, String uriStr)
+    public void formatURI(WriterI w, String uriStr)
     {
-        try {
-            Pair<String, String> pName = prefixMap.abbrev(uriStr) ;
-            // Check if legal
-            if ( pName != null )
+        Pair<String, String> pName = prefixMap.abbrev(uriStr) ;
+        // Check if legal
+        if ( pName != null )
+        {
+            // Check legal - need to check legal, not for illegal.
+            String pref = pName.getLeft() ;
+            String ln = pName.getRight() ;
+            if ( safeForPrefix(pref) && safeForPrefixLocalname(ln) )
             {
-                // Check legal - need to check legal, not for illegal.
-                String pref = pName.getLeft() ;
-                String ln = pName.getRight() ;
-                if ( safeForPrefix(pref) && safeForPrefixLocalname(ln) )
-                {
-                    w.write(pName.getLeft()) ;
-                    w.write(':') ;
-                    w.write(pName.getRight()) ;
-                    return ;
-                }
+                w.print(pName.getLeft()) ;
+                w.print(':') ;
+                w.print(pName.getRight()) ;
+                return ;
             }
-        
-            // Attemp base abbreviation.
-            if ( baseIRI != null )
+        }
+
+        // Attempt base abbreviation.
+        if ( baseIRI != null )
+        {
+            String x = abbrevByBase(uriStr, baseIRI) ;
+            if ( x != null )
             {
-                String x = abbrevByBase(uriStr, baseIRI) ;
-                if ( x != null )
-                {
-                    w.write('<') ;
-                    w.write(x) ;
-                    w.write('>') ;
-                    return ;
-                }
+                w.print('<') ;
+                w.print(x) ;
+                w.print('>') ;
+                return ;
             }
-        } catch (IOException ex) { IO.exception(ex) ; }
-        
+        }
+
+        // else
         super.formatURI(w, uriStr) ;
     }
     
@@ -116,27 +121,23 @@ public class NodeFormatterTTL extends No
     }
 
 //    @Override
-//    public void formatVar(Writer w, String name)
+//    public void formatVar(WriterI w, String name)
 
 //    @Override
-//    public void formatBNode(Writer w, String label)
+//    public void formatBNode(WriterI w, String label)
+    
+    @Override
+    public void formatBNode(WriterI w, Node n)
+    {
+        String x = nodeToLabel.get(null, n) ;
+        w.print(x) ; 
+    }
 
 //    @Override
-//    public void formatLitString(Writer w, String lex)
+//    public void formatLitString(WriterI w, String lex)
 
 //    @Override
-//    public void formatLitLang(Writer w, String lex, String langTag)
-
-    /* PN_CHARS_BASE includes escapes. 
-     * 
-     *  PN_CHARS_BASE ::= [A-Z] | [a-z] | [#00C0-#00D6] | [#00D8-#00F6] | [#00F8-#02FF] | [#0370-#037D] | [#037F-#1FFF]
-     *                  | [#200C-#200D] | [#2070-#218F] | [#2C00-#2FEF] | [#3001-#D7FF] | [#F900-#FDCF] | [#FDF0-#FFFD] | [#10000-#EFFFF]
-     *                  | UCHAR
-     *  PN_CHARS_U    ::= PN_CHARS_BASE | "_"
-     *  PN_CHARS      ::= PN_CHARS_U | '-' | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040]
-     *  PN_PREFIX     ::= PN_CHARS_BASE ( ( PN_CHARS | "." )* PN_CHARS )?
-     *  PN_LOCAL      ::= ( PN_CHARS_U | [0-9] ) ( ( PN_CHARS | "." )* PN_CHARS )?
-     */
+//    public void formatLitLang(WriterI w, String lex, String langTag)
 
     /*private-testing*/ static boolean safeForPrefixLocalname(String str)
     {
@@ -150,29 +151,6 @@ public class NodeFormatterTTL extends No
         if ( idx == N ) return true ;
         idx = skip1_PN_CHARS(str, idx) ;
         return ( idx == N ) ;
-        
-//        int N = str.length();
-//        if ( N == 0 )
-//            return true ;
-//        // Test first and last.
-//        //char chFirst = str.charAt(0) ;
-//        int startIdx = 0 ;
-//        
-//        char chLast = str.charAt(N-1) ;
-//        if ( ! RiotChars.isA2ZN(chLast) &&
-//             chLast != '_' )
-//            return false ;
-//        int lastIdx = N-2 ;
-//        
-//        for ( int i = startIdx ; i <= lastIdx ; i++ )
-//        {
-//            char ch = str.charAt(i) ;
-//            if ( ! RiotChars.isA2ZN(ch) &&
-//                 ch != '_' &&
-//                 ch != '.' )
-//                return false ;
-//        }
-//        return true ;
     }
 
     private static boolean is_PN_CHARS_BASE(int ch)    { return RiotChars.isAlpha(ch) ; }
@@ -223,45 +201,44 @@ public class NodeFormatterTTL extends No
     private static final String dtBoolean   = XSDDatatype.XSDboolean.getURI() ;
 
     @Override
-    public void formatLitDT(Writer w, String lex, String datatypeURI)
+    public void formatLitDT(WriterI w, String lex, String datatypeURI)
     {
-        try {
-            if ( dtDecimal.equals(datatypeURI) )
+        if ( dtDecimal.equals(datatypeURI) )
+        {
+            if ( validDecimal(lex) )
             {
-                if ( validDecimal(lex) )
-                {
-                    w.write(lex) ;
-                    return ;
-                }
+                w.print(lex) ;
+                return ;
             }
-            else if ( dtInteger.equals(datatypeURI) )
+        }
+        else if ( dtInteger.equals(datatypeURI) )
+        {
+            if ( validInteger(lex) )
             {
-                if ( validInteger(lex) )
-                {
-                    w.write(lex) ;
-                    return ;
-                }
+                w.print(lex) ;
+                return ;
             }
-            if ( dtDouble.equals(datatypeURI) )
+        }
+        if ( dtDouble.equals(datatypeURI) )
+        {
+            if ( validDouble(lex) )
             {
-                if ( validDouble(lex) )
-                {
-                    w.write(lex) ;
-                    return ; 
-                }
+                w.print(lex) ;
+                return ; 
             }
-            // Boolean
-            if ( dtBoolean.equals(datatypeURI) )
+        }
+        // Boolean
+        if ( dtBoolean.equals(datatypeURI) )
+        {
+            // We leave "0" and "1" as-is assumign that if written like that, there was a reason.
+            if ( lex.equals("true") || lex.equals("false") )
             {
-                // We leave "0" and "1" as-is assumign that if written like that, there was a reason.
-                if ( lex.equals("true") || lex.equals("false") )
-                {
-                    w.write(lex) ;
-                    return ; 
-                }
+                w.print(lex) ;
+                return ; 
             }
-        } catch (IOException ex) { IO.exception(ex) ; } 
-
+        }
+        
+        // else.
         super.formatLitDT(w, lex, datatypeURI) ;
     }
 

Added: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/OutputUtils.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/OutputUtils.java?rev=1452591&view=auto
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/OutputUtils.java (added)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/OutputUtils.java Mon Mar  4 23:22:53 2013
@@ -0,0 +1,78 @@
+/*
+ * 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.out;
+
+import java.io.IOException ;
+import java.io.Writer ;
+
+import org.apache.jena.atlas.io.WriterI ;
+import org.apache.jena.atlas.lib.BitsInt ;
+import org.apache.jena.atlas.lib.Chars ;
+
+public class OutputUtils
+{
+    /** Print the number x in width hex chars.  x must fit */
+    public static void printHex(StringBuilder out, int x, int width)
+    {
+        for ( int i = width-1 ; i >= 0 ; i-- )
+            x = oneHex(out, x, i) ;
+    }
+
+    /** Print one hex digit of the number */
+    public static int oneHex(StringBuilder out, int x, int i)
+    {
+        int y = BitsInt.unpack(x, 4*i, 4*i+4) ;
+        char charHex = Chars.hexDigitsUC[y] ;
+        out.append(charHex) ; 
+        return BitsInt.clear(x, 4*i, 4*i+4) ;
+    }
+    
+    /** Print the number x in width hex chars.  x must fit */
+    public static void printHex(Writer out, int x, int width)
+    {
+        for ( int i = width-1 ; i >= 0 ; i-- )
+            x = oneHex(out, x, i) ;
+    }
+
+    /** Print one hex digit of the number */
+    public static int oneHex(Writer out, int x, int i)
+    {
+        int y = BitsInt.unpack(x, 4*i, 4*i+4) ;
+        char charHex = Chars.hexDigitsUC[y] ;
+        try { out.write(charHex) ; } catch (IOException ex) {} 
+        return BitsInt.clear(x, 4*i, 4*i+4) ;
+    }
+
+    /** Print the number x in width hex chars.  x must fit */
+    public static void printHex(WriterI out, int x, int width)
+    {
+        for ( int i = width-1 ; i >= 0 ; i-- )
+            x = oneHex(out, x, i) ;
+    }
+
+    /** Print one hex digit of the number */
+    public static int oneHex(WriterI out, int x, int i)
+    {
+        int y = BitsInt.unpack(x, 4*i, 4*i+4) ;
+        char charHex = Chars.hexDigitsUC[y] ;
+        out.print(charHex) ; 
+        return BitsInt.clear(x, 4*i, 4*i+4) ;
+    }
+    
+}

Modified: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/SinkQuadOutput.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/SinkQuadOutput.java?rev=1452591&r1=1452590&r2=1452591&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/SinkQuadOutput.java (original)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/SinkQuadOutput.java Mon Mar  4 23:22:53 2013
@@ -18,11 +18,10 @@
 
 package org.apache.jena.riot.out;
 
-import java.io.IOException ;
 import java.io.OutputStream ;
-import java.io.Writer ;
 
 import org.apache.jena.atlas.io.IO ;
+import org.apache.jena.atlas.io.WriterI ;
 import org.apache.jena.atlas.lib.Sink ;
 import org.apache.jena.riot.system.Prologue ;
 import org.apache.jena.riot.system.SyntaxLabels ;
@@ -34,7 +33,7 @@ import com.hp.hpl.jena.sparql.core.Quad 
 public class SinkQuadOutput implements Sink<Quad>
 {
     private Prologue prologue = null ;
-    private Writer out ;
+    private WriterI out ;
     private NodeToLabel labelPolicy = null ;
     private NodeFormatter nodeFmt = new NodeFormatterNT() ;
 
@@ -45,7 +44,7 @@ public class SinkQuadOutput implements S
     
     public SinkQuadOutput(OutputStream outs, Prologue prologue, NodeToLabel labels)
     {
-        out = IO.asBufferedUTF8(outs) ;
+        out = IO.wrapUTF8(outs) ;
         setPrologue(prologue) ;
         setLabelPolicy(labels) ;
     }
@@ -64,26 +63,24 @@ public class SinkQuadOutput implements S
     @Override
     public void send(Quad quad)
     {
-        try {
-            Node s = quad.getSubject() ;
-            Node p = quad.getPredicate() ;
-            Node o = quad.getObject() ;
-            Node g = quad.getGraph() ;
-
-            nodeFmt.format(out, s) ;
-            out.write(" ") ;
-            nodeFmt.format(out, p) ;
-            out.write(" ") ;
-            nodeFmt.format(out, o) ;
-
-            if ( outputGraphSlot(g) ) 
-            {
-                out.write(" ") ;
-                nodeFmt.format(out, g) ;
-            }
+        Node s = quad.getSubject() ;
+        Node p = quad.getPredicate() ;
+        Node o = quad.getObject() ;
+        Node g = quad.getGraph() ;
+
+        nodeFmt.format(out, s) ;
+        out.print(" ") ;
+        nodeFmt.format(out, p) ;
+        out.print(" ") ;
+        nodeFmt.format(out, o) ;
+
+        if ( outputGraphSlot(g) ) 
+        {
+            out.print(" ") ;
+            nodeFmt.format(out, g) ;
+        }
 
-            out.write(" .\n") ;
-        } catch (IOException ex) { IO.exception(ex) ; }
+        out.print(" .\n") ;
     }
     
     private static boolean outputGraphSlot(Node g)
@@ -94,7 +91,7 @@ public class SinkQuadOutput implements S
     @Override
     public void flush()
     {
-        try { out.flush() ; } catch (IOException ex) { IO.exception(ex) ; }
+        IO.flush(out) ;
     }
 
     @Override

Modified: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/SinkTripleOutput.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/SinkTripleOutput.java?rev=1452591&r1=1452590&r2=1452591&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/SinkTripleOutput.java (original)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/out/SinkTripleOutput.java Mon Mar  4 23:22:53 2013
@@ -18,12 +18,10 @@
 
 package org.apache.jena.riot.out;
 
-import java.io.IOException ;
 import java.io.OutputStream ;
-import java.io.Writer ;
-import java.nio.charset.CharsetEncoder ;
 
 import org.apache.jena.atlas.io.IO ;
+import org.apache.jena.atlas.io.WriterI ;
 import org.apache.jena.atlas.lib.Sink ;
 import org.apache.jena.riot.system.Prologue ;
 import org.apache.jena.riot.system.SyntaxLabels ;
@@ -34,9 +32,8 @@ import com.hp.hpl.jena.graph.Triple ;
 /** A class that print triples, N-triples style */ 
 public class SinkTripleOutput implements Sink<Triple>
 {
-    private CharsetEncoder encoder ;
     private Prologue prologue = null ;
-    private Writer out ;
+    private final WriterI out ;
     private NodeToLabel labelPolicy = null ;
     
     private NodeFormatter nodeFmt = new NodeFormatterNT() ;
@@ -48,7 +45,7 @@ public class SinkTripleOutput implements
     
     public SinkTripleOutput(OutputStream outs, Prologue prologue, NodeToLabel labels)
     {
-        out = IO.asBufferedUTF8(outs) ;
+        out = IO.wrapUTF8(outs) ;
         setPrologue(prologue) ;
         setLabelPolicy(labels) ;
     }
@@ -67,18 +64,16 @@ public class SinkTripleOutput implements
     @Override
     public void send(Triple triple)
     {
-        try {
             Node s = triple.getSubject() ;
             Node p = triple.getPredicate() ;
             Node o = triple.getObject() ;
 
             nodeFmt.format(out, s) ;
-            out.write(" ") ;
+            out.print(" ") ;
             nodeFmt.format(out, p) ;
-            out.write(" ") ;
+            out.print(" ") ;
             nodeFmt.format(out, o) ;
-            out.write(" .\n") ;
-        } catch (IOException ex) { IO.exception(ex) ; }
+            out.print(" .\n") ;
     }
 
     @Override

Added: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/system/IO_Jena2.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/system/IO_Jena2.java?rev=1452591&view=auto
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/system/IO_Jena2.java (added)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/system/IO_Jena2.java Mon Mar  4 23:22:53 2013
@@ -0,0 +1,124 @@
+/**
+ * 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.Collection ;
+import java.util.HashMap ;
+import java.util.Map ;
+
+import org.apache.jena.riot.RDFFormat ;
+import org.apache.jena.riot.adapters.RDFWriterRIOT ;
+
+import com.hp.hpl.jena.Jena ;
+import com.hp.hpl.jena.n3.N3JenaWriter ;
+import com.hp.hpl.jena.rdf.model.impl.RDFWriterFImpl ;
+
+public class IO_Jena2
+{
+    // Jena writer adapters
+    // To adapters.JenaReadersWriters
+    public static class RDFWriterRIOT_RDFXML        extends RDFWriterRIOT   { public RDFWriterRIOT_RDFXML()         { super("RDF/XML") ; } }
+    public static class RDFWriterRIOT_RDFXMLAbbrev  extends RDFWriterRIOT   { public RDFWriterRIOT_RDFXMLAbbrev()   { super("RDF/XML-ABBREV") ; } }
+    public static class RDFWriterRIOT_NTriples      extends RDFWriterRIOT   { public RDFWriterRIOT_NTriples()       { super("N-TRIPLES") ; } }
+    public static class RDFWriterRIOT_N3            extends RDFWriterRIOT   { public RDFWriterRIOT_N3()             { super("N3") ; } }
+    public static class RDFWriterRIOT_N3_PP         extends RDFWriterRIOT   { public RDFWriterRIOT_N3_PP()          { super(N3JenaWriter.n3WriterPrettyPrinter) ; } }
+    public static class RDFWriterRIOT_N3Plain       extends RDFWriterRIOT   { public RDFWriterRIOT_N3Plain()        { super(N3JenaWriter.n3WriterPlain) ; } }
+    public static class RDFWriterRIOT_N3Triples     extends RDFWriterRIOT   { public RDFWriterRIOT_N3Triples()      { super(N3JenaWriter.n3WriterTriples) ; } }
+    public static class RDFWriterRIOT_N3TriplesAlt  extends RDFWriterRIOT   { public RDFWriterRIOT_N3TriplesAlt()   { super(N3JenaWriter.n3WriterTriplesAlt) ; } }
+    public static class RDFWriterRIOT_Turtle        extends RDFWriterRIOT   { public RDFWriterRIOT_Turtle()         { super(N3JenaWriter.turtleWriter) ; } }
+    public static class RDFWriterRIOT_Turtle1       extends RDFWriterRIOT   { public RDFWriterRIOT_Turtle1()        { super(N3JenaWriter.turtleWriterAlt1) ; } }
+    public static class RDFWriterRIOT_Turtle2       extends RDFWriterRIOT   { public RDFWriterRIOT_Turtle2()        { super(N3JenaWriter.turtleWriterAlt2) ; } }
+    public static class RDFWriterRIOT_RDFJSON       extends RDFWriterRIOT   { public RDFWriterRIOT_RDFJSON()        { super("RDF/JSON") ; } }
+    
+    private static Map<String, RDFFormat> mapJenaNameToFormat               = new HashMap<String, RDFFormat>() ;
+
+    /** return the RDFFormat for the existing Jena writer name, or null */ 
+    public static RDFFormat getFormatForJenaWriter(String jenaName) { return mapJenaNameToFormat.get(jenaName) ; }
+
+    /** Register an RDFFormat for a Jena writer name */ 
+    public static void setFormatForJenaWriter(String jenaName, RDFFormat format) { mapJenaNameToFormat.put(jenaName, format) ; }
+
+    /** Return a collection of jena writer names */ 
+    public static Collection<String> getJenaWriterNames() { return mapJenaNameToFormat.keySet() ; }
+    
+    public static void wireIntoJenaW()
+    {
+        setFormatForJenaWriter("RDF/XML",                           RDFFormat.RDFXML_PLAIN) ;
+        setFormatForJenaWriter("RDF/XML-ABBREV",                    RDFFormat.RDFXML_ABBREV) ;
+        setFormatForJenaWriter("N-TRIPLE",                          RDFFormat.NTRIPLES) ;
+        setFormatForJenaWriter("NT",                                RDFFormat.NTRIPLES) ;
+        setFormatForJenaWriter("N-TRIPLES",                         RDFFormat.NTRIPLES) ;
+        setFormatForJenaWriter("N-Triples",                         RDFFormat.NTRIPLES) ;
+        setFormatForJenaWriter("N3",                                RDFFormat.TURTLE) ;
+        setFormatForJenaWriter(N3JenaWriter.n3WriterPrettyPrinter,  RDFFormat.TURTLE_PRETTY) ;
+        setFormatForJenaWriter(N3JenaWriter.n3WriterPlain,          RDFFormat.TURTLE_BLOCKS) ;
+        setFormatForJenaWriter(N3JenaWriter.n3WriterTriples,        RDFFormat.TURTLE_FLAT) ;
+        setFormatForJenaWriter(N3JenaWriter.n3WriterTriplesAlt,     RDFFormat.TURTLE_FLAT) ;
+        setFormatForJenaWriter(N3JenaWriter.turtleWriter,           RDFFormat.TURTLE) ;
+        setFormatForJenaWriter(N3JenaWriter.turtleWriterAlt1,       RDFFormat.TURTLE) ;
+        setFormatForJenaWriter(N3JenaWriter.turtleWriterAlt2,       RDFFormat.TURTLE) ;
+        
+        setFormatForJenaWriter("RDF/JSON",                          RDFFormat.RDFJSON) ;
+        setFormatForJenaWriter("RDFJSON",                           RDFFormat.RDFJSON) ;
+        
+//        RDFWriterFImpl.LANGS
+//        RDFWriterFImpl.DEFAULTWRITER
+        RDFWriterFImpl.setBaseWriterClassName("RDF/XML",            RDFWriterRIOT_RDFXML.class.getName()) ;
+        RDFWriterFImpl.setBaseWriterClassName("RDF/XML-ABBREV",     RDFWriterRIOT_RDFXMLAbbrev.class.getName()) ;
+        RDFWriterFImpl.setBaseWriterClassName("N-TRIPLE",           RDFWriterRIOT_NTriples.class.getName()) ;
+        RDFWriterFImpl.setBaseWriterClassName("N-TRIPLES",          RDFWriterRIOT_NTriples.class.getName()) ;
+        RDFWriterFImpl.setBaseWriterClassName("N-Triples",          RDFWriterRIOT_NTriples.class.getName()) ;
+        RDFWriterFImpl.setBaseWriterClassName("NT",                 RDFWriterRIOT_NTriples.class.getName()) ;
+        RDFWriterFImpl.setBaseWriterClassName("N3",                 RDFWriterRIOT_N3.class.getName()) ;
+        
+        RDFWriterFImpl.setBaseWriterClassName(N3JenaWriter.n3WriterPrettyPrinter,   RDFWriterRIOT_N3_PP.class.getName()) ;
+        RDFWriterFImpl.setBaseWriterClassName(N3JenaWriter.n3WriterPlain,           RDFWriterRIOT_N3Plain.class.getName()) ;
+        RDFWriterFImpl.setBaseWriterClassName(N3JenaWriter.n3WriterTriples,         RDFWriterRIOT_N3Triples.class.getName()) ;
+        RDFWriterFImpl.setBaseWriterClassName(N3JenaWriter.n3WriterTriplesAlt,      RDFWriterRIOT_N3TriplesAlt.class.getName()) ;
+        
+        RDFWriterFImpl.setBaseWriterClassName(N3JenaWriter.turtleWriter,            RDFWriterRIOT_Turtle.class.getName()) ;
+        RDFWriterFImpl.setBaseWriterClassName(N3JenaWriter.turtleWriterAlt1,        RDFWriterRIOT_Turtle1.class.getName()) ;
+        RDFWriterFImpl.setBaseWriterClassName(N3JenaWriter.turtleWriterAlt2,        RDFWriterRIOT_Turtle2.class.getName()) ;
+        
+        RDFWriterFImpl.setBaseWriterClassName("RDF/JSON",       RDFWriterRIOT_RDFJSON.class.getName()) ;
+        RDFWriterFImpl.setBaseWriterClassName("RDFJSON",        RDFWriterRIOT_RDFJSON.class.getName()) ;
+    }
+    
+    public static void resetJenaW()
+    {
+        // This is the old Jena configuration (bugs and all) 
+        RDFWriterFImpl.setBaseWriterClassName("RDF/XML",        Jena.PATH + ".xmloutput.impl.Basic") ;
+        RDFWriterFImpl.setBaseWriterClassName("RDF/XML-ABBREV", Jena.PATH + ".xmloutput.impl.Abbreviated") ;
+
+        RDFWriterFImpl.setBaseWriterClassName("N-TRIPLE",       Jena.PATH + ".rdf.model.impl.NTripleWriter") ;
+        RDFWriterFImpl.setBaseWriterClassName("N-TRIPLES",      Jena.PATH + ".rdf.model.impl.NTripleWriter") ;
+        RDFWriterFImpl.setBaseWriterClassName("N-Triples",      Jena.PATH + ".rdf.model.impl.NTripleWriter") ;
+        
+        RDFWriterFImpl.setBaseWriterClassName("N3",             Jena.PATH + ".n3.N3JenaWriter") ;         
+        RDFWriterFImpl.setBaseWriterClassName(N3JenaWriter.n3WriterPrettyPrinter,    Jena.PATH + ".n3.N3JenaWriterPP") ;
+        RDFWriterFImpl.setBaseWriterClassName(N3JenaWriter.n3WriterPlain,           Jena.PATH + ".n3.N3TurtleJenaWriter") ;
+        RDFWriterFImpl.setBaseWriterClassName(N3JenaWriter.n3WriterTriples,         Jena.PATH + ".n3.N3TurtleJenaWriter") ;
+        RDFWriterFImpl.setBaseWriterClassName(N3JenaWriter.n3WriterTriplesAlt,      Jena.PATH + ".n3.N3JenaWriterTriples") ;
+        RDFWriterFImpl.setBaseWriterClassName(N3JenaWriter.turtleWriter,            Jena.PATH + ".n3.N3TurtleJenaWriter") ;
+        RDFWriterFImpl.setBaseWriterClassName(N3JenaWriter.turtleWriterAlt1,        Jena.PATH + ".n3.N3TurtleJenaWriter") ;
+        RDFWriterFImpl.setBaseWriterClassName(N3JenaWriter.turtleWriterAlt2,        Jena.PATH + ".n3.N3TurtleJenaWriter") ;
+        
+    }
+}
+