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 2012/01/12 14:13:13 UTC

svn commit: r1230511 - in /incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena: atlas/io/BufferingWriter.java atlas/io/Writer2.java riot/out/SinkQuadOutput.java riot/out/SinkTripleOutput.java

Author: andy
Date: Thu Jan 12 13:13:12 2012
New Revision: 1230511

URL: http://svn.apache.org/viewvc?rev=1230511&view=rev
Log:
Temporary fixes for buffered writer performance problems.

Added:
    incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/io/Writer2.java
Modified:
    incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/io/BufferingWriter.java
    incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/out/SinkQuadOutput.java
    incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/out/SinkTripleOutput.java

Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/io/BufferingWriter.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/io/BufferingWriter.java?rev=1230511&r1=1230510&r2=1230511&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/io/BufferingWriter.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/io/BufferingWriter.java Thu Jan 12 13:13:12 2012
@@ -52,6 +52,7 @@ import org.openjena.atlas.logging.Log ;
 
 public final class BufferingWriter extends Writer
 {
+    
     // ***** Suspiciously slow.
     // ***** DO NOT USE
     // Better to buffer in character space the convert in larger blocks.

Added: incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/io/Writer2.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/io/Writer2.java?rev=1230511&view=auto
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/io/Writer2.java (added)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/io/Writer2.java Thu Jan 12 13:13:12 2012
@@ -0,0 +1,60 @@
+/**
+ * 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.openjena.atlas.io;
+
+import java.io.IOException ;
+import java.io.Writer ;
+
+import org.openjena.atlas.lib.Closeable ;
+
+/** A Writer, without the checked exceptions. */
+
+public final class Writer2 implements Closeable
+{
+    private final Writer writer ;
+
+    public static Writer2 wrap(Writer writer) { return new Writer2(writer) ; }
+    
+    public Writer2(Writer writer) { this.writer = writer ; }
+    
+
+    public void output(int 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) ; } }
+
+    public void output(String string, int off, int len) throws IOException
+    { try { writer.write(string, off, len) ; } catch (IOException ex) { IO.exception(ex) ; } }
+    
+    public void output(char[] cbuf) throws IOException
+    { try { writer.write(cbuf) ; } catch (IOException ex) { IO.exception(ex) ; } }
+
+    public void output(char[] cbuf, int off, int len) throws IOException
+    { try { writer.write(cbuf, off, len) ; } catch (IOException ex) { IO.exception(ex) ; } }
+    
+    public void flush()
+    { try { writer.flush() ; } catch (IOException ex) { IO.exception(ex) ; } }
+
+    @Override
+    public void close()
+    { try { writer.close() ; } catch (IOException ex) { IO.exception(ex) ; } }
+
+}
+

Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/out/SinkQuadOutput.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/out/SinkQuadOutput.java?rev=1230511&r1=1230510&r2=1230511&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/out/SinkQuadOutput.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/out/SinkQuadOutput.java Thu Jan 12 13:13:12 2012
@@ -18,11 +18,11 @@
 
 package org.openjena.riot.out;
 
+import java.io.IOException ;
 import java.io.OutputStream ;
-import java.nio.charset.CharsetEncoder ;
+import java.io.Writer ;
 
-import org.openjena.atlas.io.BufferingWriter ;
-import org.openjena.atlas.lib.Chars ;
+import org.openjena.atlas.io.IO ;
 import org.openjena.atlas.lib.Sink ;
 import org.openjena.riot.system.Prologue ;
 import org.openjena.riot.system.SyntaxLabels ;
@@ -33,9 +33,8 @@ import com.hp.hpl.jena.sparql.core.Quad 
 /** A class that print quads, N-Quads style */ 
 public class SinkQuadOutput implements Sink<Quad>
 {
-    private CharsetEncoder encoder ;
     private Prologue prologue = null ;
-    private BufferingWriter out ;
+    private Writer out ;
     private NodeToLabel labelPolicy = null ;
     private NodeFormatter nodeFmt = new NodeFormatterNT() ;
 
@@ -46,8 +45,7 @@ public class SinkQuadOutput implements S
     
     public SinkQuadOutput(OutputStream outs, Prologue prologue, NodeToLabel labels)
     {
-        encoder = Chars.charsetUTF8.newEncoder() ;
-        out = BufferingWriter.create(outs) ;
+        out = IO.asBufferedUTF8(outs) ;
         setPrologue(prologue) ;
         setLabelPolicy(labels) ;
     }
@@ -63,34 +61,29 @@ public class SinkQuadOutput implements S
         this.labelPolicy = labels ;
     }
 
-
-    @Override
-    public void flush()
-    {
-        out.flush() ;
-    }
-
     @Override
     public void send(Quad quad)
     {
-        Node s = quad.getSubject() ;
-        Node p = quad.getPredicate() ;
-        Node o = quad.getObject() ;
-        Node g = quad.getGraph() ;
-        
-        nodeFmt.format(out, s) ;
-        out.output(" ") ;
-        nodeFmt.format(out, p) ;
-        out.output(" ") ;
-        nodeFmt.format(out, o) ;
-        
-        if ( outputGraphSlot(g) ) 
-        {
-            out.output(" ") ;
-            nodeFmt.format(out, g) ;
-        }
-            
-        out.output(" .\n") ;
+        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) ;
+            }
+
+            out.write(" .\n") ;
+        } catch (IOException ex) { IO.exception(ex) ; }
     }
     
     private static boolean outputGraphSlot(Node g)
@@ -99,8 +92,14 @@ public class SinkQuadOutput implements S
     }
 
     @Override
+    public void flush()
+    {
+        try { out.flush() ; } catch (IOException ex) { IO.exception(ex) ; }
+    }
+
+    @Override
     public void close()
     {
-        flush();
+        try { out.close() ; } catch (IOException ex) { IO.exception(ex) ; }
     }
 }

Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/out/SinkTripleOutput.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/out/SinkTripleOutput.java?rev=1230511&r1=1230510&r2=1230511&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/out/SinkTripleOutput.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/out/SinkTripleOutput.java Thu Jan 12 13:13:12 2012
@@ -18,11 +18,12 @@
 
 package org.openjena.riot.out;
 
+import java.io.IOException ;
 import java.io.OutputStream ;
+import java.io.Writer ;
 import java.nio.charset.CharsetEncoder ;
 
-import org.openjena.atlas.io.BufferingWriter ;
-import org.openjena.atlas.lib.Chars ;
+import org.openjena.atlas.io.IO ;
 import org.openjena.atlas.lib.Sink ;
 import org.openjena.riot.system.Prologue ;
 import org.openjena.riot.system.SyntaxLabels ;
@@ -36,7 +37,7 @@ public class SinkTripleOutput implements
     // TODO ASCII version
     private CharsetEncoder encoder ;
     private Prologue prologue = null ;
-    private BufferingWriter out ;
+    private Writer out ;
     private NodeToLabel labelPolicy = null ;
     
     private NodeFormatter nodeFmt = new NodeFormatterNT() ;
@@ -48,9 +49,7 @@ public class SinkTripleOutput implements
     
     public SinkTripleOutput(OutputStream outs, Prologue prologue, NodeToLabel labels)
     {
-        //encoder = Chars.charsetUTF8.newEncoder() ;
-        encoder = Chars.charsetASCII.newEncoder() ;
-        out = BufferingWriter.create(outs) ;
+        out = IO.asBufferedUTF8(outs) ;
         setPrologue(prologue) ;
         setLabelPolicy(labels) ;
     }
@@ -67,29 +66,31 @@ public class SinkTripleOutput implements
     }
     
     @Override
-    public void flush()
+    public void send(Triple triple)
     {
-        out.flush() ;
+        try {
+            Node s = triple.getSubject() ;
+            Node p = triple.getPredicate() ;
+            Node o = triple.getObject() ;
+
+            nodeFmt.format(out, s) ;
+            out.write(" ") ;
+            nodeFmt.format(out, p) ;
+            out.write(" ") ;
+            nodeFmt.format(out, o) ;
+            out.write(" .\n") ;
+        } catch (IOException ex) { IO.exception(ex) ; }
     }
 
     @Override
-    public void send(Triple triple)
+    public void flush()
     {
-        Node s = triple.getSubject() ;
-        Node p = triple.getPredicate() ;
-        Node o = triple.getObject() ;
-        
-        nodeFmt.format(out, s) ;
-        out.output(" ") ;
-        nodeFmt.format(out, p) ;
-        out.output(" ") ;
-        nodeFmt.format(out, o) ;
-        out.output(" .\n") ;
+        try { out.flush() ; } catch (IOException ex) { IO.exception(ex) ; }
     }
 
     @Override
     public void close()
     {
-        flush();
+        try { out.close() ; } catch (IOException ex) { IO.exception(ex) ; }
     }
 }