jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1225956 - in /incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena: atlas/io/BlockUTF8.java atlas/io/BufferingWriter.java atlas/io/IndentedWriter.java atlas/lib/Bytes.java riot/system/JenaWriterBase.java
Date Fri, 30 Dec 2011 22:46:29 GMT
Author: andy
Date: Fri Dec 30 22:46:28 2011
New Revision: 1225956

URL: http://svn.apache.org/viewvc?rev=1225956&view=rev
Log:
Tidy conversion to/from UTF-8 bytes after testing.

Modified:
    incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/io/BlockUTF8.java
    incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/io/BufferingWriter.java
    incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/io/IndentedWriter.java
    incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/lib/Bytes.java
    incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/system/JenaWriterBase.java

Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/io/BlockUTF8.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/io/BlockUTF8.java?rev=1225956&r1=1225955&r2=1225956&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/io/BlockUTF8.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/io/BlockUTF8.java Fri
Dec 30 22:46:28 2011
@@ -30,40 +30,78 @@ import org.openjena.atlas.AtlasException
  * The usual Charset encoders/decoders are expensive to start up - they are also
  * not thread safe. Sometimes we want to convert 10's of chars and UTF-8 can be
  * done in code with no lookup tables (which, if used, are cache-unfriendly).
+ * 
+ * This code is thread safe.  It uses code in the hope that JITting will
+ * make it fast if used heavily.
  */
 
 public class BlockUTF8
 {
-    private static Convert converter = new ConvertUTF8() ;
-    private static Convert asciiConvert = new ConvertAscii() ;
+    // It seems that chars -> bytes (on <100char strings) is faster with BlockUTF8
+    // but the conversion from bytes to string is faster with decoders. 
+    
+    private static final Convert converter = new ConvertUTF8() ;
+    private static final Convert asciiConvert = new ConvertAscii() ;
 
+    /** Convert the bytes in the ByteBuffer to characters in the CharBuffer.
+     * The CharBuffer must be large enough. 
+     */
     public static void toChars(ByteBuffer bb, CharBuffer cb)
     {
         int len = bb.remaining() ;
 
-        for (int i = 0; i < len;)
+        for (int i = 0; i < len; )
         {
-            i += converter.convertBytesToChar(bb, cb) ;
+            //i += converter.convertBytesToChar(bb, cb) ;
+            i += _convertBytesToChar(bb, cb) ;
         }
     }
+    
+    /** Make a string from UTF-8 bytes in a ByteBuffer */ 
+    public static String toString(ByteBuffer bb)
+    {
+        // I think that the copy from some mutable collector to immutable string is inevitable
in java.  
+        int len = bb.remaining() ;
+        CharBuffer cb = CharBuffer.allocate(len) ;
+        toChars(bb, cb) ;
+        return new String(cb.array(), 0, cb.position()) ;
+    }
 
+    /** Convert characters to UTF-8 bytes in the ByteBuffer.
+     * The ByteBuffer must be large enough. 
+     */
+    public static void fromChars(CharSequence cs, ByteBuffer bb)
+    {
+        int len = cs.length() ;
+        for (int i = 0; i < len; i++)
+        {
+            char c = cs.charAt(i) ;
+            //converter.convertCharToBytes(c, bb) ;
+            _convertCharToBytes(c, bb) ;
+        }
+    }
+    
+    /** Convert charcaters to UTF-8 bytes in the ByteBuffer.
+     * The ByteBuffer must be large enough. 
+     */
     public static void fromChars(CharBuffer cb, ByteBuffer bb)
     {
+        // CharBuffers are CharSequences but charAt(i) adds a layer of work.
         int len = cb.remaining() ;
-
         for (int i = 0; i < len; i++)
         {
-            converter.convertCharToBytes(cb, bb) ;
+            char c = cb.get() ;
+            converter.convertCharToBytes(c, bb) ;
         }
     }
 
-    interface Convert
+    private interface Convert
     {
         /** Return number of bytes consumed */
         int convertBytesToChar(ByteBuffer bb, CharBuffer cb) ;
 
         /** Return number of bytes produced */
-        int convertCharToBytes(CharBuffer cb, ByteBuffer bb) ;
+        int convertCharToBytes(char c, ByteBuffer bb) ;
     }
 
     // ASCII
@@ -81,11 +119,10 @@ public class BlockUTF8
         }
 
         @Override
-        public int convertCharToBytes(CharBuffer cb, ByteBuffer bb)
+        public int convertCharToBytes(char c, ByteBuffer bb)
         {
-            char c = cb.get() ;
             byte b = (byte)(c | 0xFF) ;
-            bb.put(bb) ;
+            bb.put(b) ;
             return 1 ;
         }
     }
@@ -93,175 +130,184 @@ public class BlockUTF8
     private static final class ConvertUTF8 implements Convert
     {
         @Override
-        public int convertBytesToChar(ByteBuffer bb, CharBuffer cb)
+        public final int convertBytesToChar(ByteBuffer bb, CharBuffer cb)
+        {
+            return _convertBytesToChar(bb, cb) ;
+        }
+        
+        @Override
+        public int convertCharToBytes(char ch, ByteBuffer bb)
         {
-            int x = bb.get() ;
-            if ( x > 0 && x <= 127 )
-            {
-                cb.put((char)x) ;
-                return 1 ;
-            }
-
-            // 10 => extension byte
-            // 110..... => 2 bytes
-            if ( (x & 0xE0) == 0xC0 )
-            {
-//                // Unwind.
-//                int ch = readMultiBytes(bb, x & 0x1F, 2) ;
-                int x2 = bb.get() ;
-                if ( (x2 & 0xC0) != 0x80 )
-                    //throw new AtlasException("Illegal UTF-8 processing character "+count+":
"+x2) ;
-                    throw new AtlasException(String.format("Illegal UTF-8 processing character:
0x%04X",x2)) ;
-                // 6 bits of x2
-                int ch = ( (x&0x1F) << 6) | (x2 & 0x3F); 
-                cb.put((char)ch) ;
-                return 2 ;
-                
-            }
-            //  1110.... => 3 bytes : 16 bits : not outside 16bit chars 
-            if ( (x & 0xF0) == 0xE0 ) 
-            {
-                int ch = readMultiBytes(bb, x & 0x0F, 3) ;
-                cb.put((char)ch) ;
-                return 3 ;
-            }
-
-            // Looking like 4 byte charcater.
-            // 11110zzz => 4 bytes.
-            if ( (x & 0xF8) == 0xF0 )
-            {
-                int ch = readMultiBytes(bb, x & 0x08, 4) ;
-                char chars[] = Character.toChars(ch) ;
-                cb.put(chars) ;
-                return 4 ;
-            }
-            else 
-            {
-                IO.exception(new IOException("Illegal UTF-8: "+x)) ;
-                return -1 ;
-            }
+            return _convertCharToBytes(ch, bb) ;
+        }
+    }
+
+    static int _convertBytesToChar(ByteBuffer bb, CharBuffer cb)
+    {
+        int x = bb.get() ;
+        if ( x > 0 && x <= 127 )
+        {
+            cb.put((char)x) ;
+            return 1 ;
+        }
+
+        // 10 => extension byte
+        // 110..... => 2 bytes
+        if ( (x & 0xE0) == 0xC0 )
+        {
+//          // Unwind.
+//          int ch = readMultiBytes(bb, x & 0x1F, 2) ;
+            int x2 = bb.get() ;
+            if ( (x2 & 0xC0) != 0x80 )
+                //throw new AtlasException("Illegal UTF-8 processing character "+count+":
"+x2) ;
+                throw new AtlasException(String.format("Illegal UTF-8 processing character:
0x%04X",x2)) ;
+            // 6 bits of x2
+            int ch = ( (x&0x1F) << 6) | (x2 & 0x3F); 
+            cb.put((char)ch) ;
+            return 2 ;
+
+        }
+        //  1110.... => 3 bytes : 16 bits : not outside 16bit chars 
+        if ( (x & 0xF0) == 0xE0 ) 
+        {
+            int ch = readMultiBytes(bb, x & 0x0F, 3) ;
+            cb.put((char)ch) ;
+            return 3 ;
+        }
+
+        // Looking like 4 byte charcater.
+        // 11110zzz => 4 bytes.
+        if ( (x & 0xF8) == 0xF0 )
+        {
+            int ch = readMultiBytes(bb, x & 0x08, 4) ;
+            char chars[] = Character.toChars(ch) ;
+            cb.put(chars) ;
+            return 4 ;
+        }
+        else 
+        {
+            IO.exception(new IOException("Illegal UTF-8: "+x)) ;
+            return -1 ;
+        }
 
 //            // This test will go off.  We're processing a 4 byte sequence but Java only
supports 16 bit chars. 
 //            if ( ch > Character.MAX_VALUE )
 //                throw new AtlasException("Out of range character (must use a surrogate
pair)") ;
 //            if ( ! Character.isDefined(ch) ) throw new AtlasException(String.format("Undefined
codepoint: 0x%04X", ch)) ;
 //            return ch ;
+    }
+
+    private static int readMultiBytes(ByteBuffer input, int start, int len) //throws IOException
+    {
+        int x = start ;
+        for ( int i = 0 ; i < len-1 ; i++ )
+        {
+            int x2 = input.get() ;
+            if ( x2 == -1 )
+                throw new AtlasException("Premature end to UTF-8 sequence at end of input")
;
+            
+            if ( (x2 & 0xC0) != 0x80 )
+                //throw new AtlasException("Illegal UTF-8 processing character "+count+":
"+x2) ;
+                throw new AtlasException(String.format("Illegal UTF-8 processing character:
0x%04X",x2)) ;
+            // 6 bits of x2
+            x = (x << 6) | (x2 & 0x3F); 
         }
+        return x ;
+    }
 
-        private static int readMultiBytes(ByteBuffer input, int start, int len) //throws
IOException
+    public static int _convertCharToBytes(char ch, ByteBuffer bb)
+    {
+        if ( ch != 0 && ch <= 127 )
         {
-            int x = start ;
-            for ( int i = 0 ; i < len-1 ; i++ )
-            {
-                int x2 = input.get() ;
-                if ( x2 == -1 )
-                    throw new AtlasException("Premature end to UTF-8 sequence at end of input")
;
-                
-                if ( (x2 & 0xC0) != 0x80 )
-                    //throw new AtlasException("Illegal UTF-8 processing character "+count+":
"+x2) ;
-                    throw new AtlasException(String.format("Illegal UTF-8 processing character:
0x%04X",x2)) ;
-                // 6 bits of x2
-                x = (x << 6) | (x2 & 0x3F); 
-            }
-            return x ;
+            // 7 bits
+            bb.put((byte)ch) ;
+            return 1 ;
         }
 
-        @Override
-        public int convertCharToBytes(CharBuffer cb, ByteBuffer bb)
+        if ( ch == 0 )
         {
-            char ch = cb.get() ;
-            if ( ch != 0 && ch <= 127 )
-            {
-                // 7 bits
-                bb.put((byte)ch) ;
-                return 1 ;
-            }
-            
-            if ( ch == 0 )
-            {
-                // Modified UTF-8.
-                bb.put((byte)0xC0) ;
-                bb.put((byte)0x80) ;
-                return 2 ;
-            }
-            
-            if ( ch <= 0x07FF )
-            {
-                // 11 bits : 110yyyyy 10xxxxxx
-                // int x1 = ( ((ch>>(11-5))&0x7) | 0xC0 ) ; outputBytes(out, x1,
2, ch) ; return ;
-                int x1 = ( ((ch>>(11-5))&0x01F ) | 0xC0 ) ; 
-                int x2 = ( (ch&0x3F)  | 0x80 ) ;
-                bb.put((byte)x1) ;
-                bb.put((byte)x2) ;
-                return 2 ;
-            }
-            if ( ch <= 0xFFFF )
-            {
-                // 16 bits : 1110aaaa  10bbbbbb  10cccccc
-                // int x1 = ( ((ch>>(16-4))&0x7) | 0xE0 ) ; outputBytes(out, x1,
3, ch) ; return ;
-                int x1 = ( ((ch>>(16-4))&0x0F) | 0xE0 ) ;
-                int x2 = ( ((ch>>6)&0x3F) | 0x80 ) ;
-                int x3 = ( (ch&0x3F) | 0x80 ) ;
-                bb.put((byte)x1) ;
-                bb.put((byte)x2) ;
-                bb.put((byte)x3) ;
-                return 3 ;
-            }
-            
-//            if ( Character.isDefined(ch) )
-//                throw new AtlasException("not a character") ;
-            
-            //if ( true ) throw new InternalErrorException("Valid code point for Java but
not encodable") ;
-            
-            // Not java, where chars are 16 bit.
-            if ( ch <= 0x1FFFFF )
-            {
-                // 21 bits : 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
-                int x1 = ( ((ch>>(21-3))&0x7) | 0xF0 ) ;
-                outputBytes(bb, x1, 4, ch) ;
-                return 4 ;
-            }
-            if ( ch <= 0x3FFFFFF )
-            {
-                // 26 bits : 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
-                int x1 = ( ((ch>>(26-2))&0x3) | 0xF8 ) ;
-                outputBytes(bb, x1, 5, ch) ;
-                return 5 ;
-            }
-
-            if ( ch <= 0x7FFFFFFF )
-            {
-                // 32 bits : 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
-                int x1 = ( ((ch>>(32-1))&0x1) | 0xFC ) ;
-                outputBytes(bb, x1, 6, ch) ;
-                return 6 ;
-            }
-            
-            return -1 ;
+            // Modified UTF-8.
+            bb.put((byte)0xC0) ;
+            bb.put((byte)0x80) ;
+            return 2 ;
         }
 
-        /*
-         * Bits 
-         * 7    U+007F      1 to 127              0xxxxxxx 
-         * 11   U+07FF      128 to 2,047          110xxxxx 10xxxxxx
-         * 16   U+FFFF      2,048 to 65,535       1110xxxx 10xxxxxx 10xxxxxx
-         * 21   U+1FFFFF    65,536 to 1,114,111   11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
-         * 26   U+3FFFFFF                         111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
-         * 31   U+7FFFFFFF                        1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
10xxxxxx
-         */
-        private static void outputBytes(ByteBuffer bb, int x1, int byteLength, int ch)
+        if ( ch <= 0x07FF )
+        {
+            // 11 bits : 110yyyyy 10xxxxxx
+            // int x1 = ( ((ch>>(11-5))&0x7) | 0xC0 ) ; outputBytes(out, x1, 2,
ch) ; return ;
+            int x1 = ( ((ch>>(11-5))&0x01F ) | 0xC0 ) ; 
+            int x2 = ( (ch&0x3F)  | 0x80 ) ;
+            bb.put((byte)x1) ;
+            bb.put((byte)x2) ;
+            return 2 ;
+        }
+        if ( ch <= 0xFFFF )
         {
-            // ByteLength = 3 => 2 byteLenth => shift=6 and shift=0  
+            // 16 bits : 1110aaaa  10bbbbbb  10cccccc
+            // int x1 = ( ((ch>>(16-4))&0x7) | 0xE0 ) ; outputBytes(out, x1, 3,
ch) ; return ;
+            int x1 = ( ((ch>>(16-4))&0x0F) | 0xE0 ) ;
+            int x2 = ( ((ch>>6)&0x3F) | 0x80 ) ;
+            int x3 = ( (ch&0x3F) | 0x80 ) ;
             bb.put((byte)x1) ;
-            byteLength-- ; // remaining bytes
-            for ( int i = 0 ; i < byteLength ; i++ )
-            {
-                // 6 Bits, loop from high to low  
-                int shift = 6*(byteLength-i-1) ;
-                int x =  (ch>>shift) & 0x3F ;
-                x = x | 0x80 ;  // 10xxxxxx
-                bb.put((byte)x) ;
-            }
+            bb.put((byte)x2) ;
+            bb.put((byte)x3) ;
+            return 3 ;
+        }
+
+        //            if ( Character.isDefined(ch) )
+        //                throw new AtlasException("not a character") ;
+
+        //if ( true ) throw new InternalErrorException("Valid code point for Java but not
encodable") ;
+
+        // Not java, where chars are 16 bit.
+        if ( ch <= 0x1FFFFF )
+        {
+            // 21 bits : 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
+            int x1 = ( ((ch>>(21-3))&0x7) | 0xF0 ) ;
+            outputBytes(bb, x1, 4, ch) ;
+            return 4 ;
+        }
+        if ( ch <= 0x3FFFFFF )
+        {
+            // 26 bits : 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
+            int x1 = ( ((ch>>(26-2))&0x3) | 0xF8 ) ;
+            outputBytes(bb, x1, 5, ch) ;
+            return 5 ;
+        }
+
+        if ( ch <= 0x7FFFFFFF )
+        {
+            // 32 bits : 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
+            int x1 = ( ((ch>>(32-1))&0x1) | 0xFC ) ;
+            outputBytes(bb, x1, 6, ch) ;
+            return 6 ;
+        }
+
+        return -1 ;
+    }
+
+    /*
+     * Bits 
+     * 7    U+007F      1 to 127              0xxxxxxx 
+     * 11   U+07FF      128 to 2,047          110xxxxx 10xxxxxx
+     * 16   U+FFFF      2,048 to 65,535       1110xxxx 10xxxxxx 10xxxxxx
+     * 21   U+1FFFFF    65,536 to 1,114,111   11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
+     * 26   U+3FFFFFF                         111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
+     * 31   U+7FFFFFFF                        1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
10xxxxxx
+     */
+    private static void outputBytes(ByteBuffer bb, int x1, int byteLength, int ch)
+    {
+        // ByteLength = 3 => 2 byteLenth => shift=6 and shift=0  
+        bb.put((byte)x1) ;
+        byteLength-- ; // remaining bytes
+        for ( int i = 0 ; i < byteLength ; i++ )
+        {
+            // 6 Bits, loop from high to low  
+            int shift = 6*(byteLength-i-1) ;
+            int x =  (ch>>shift) & 0x3F ;
+            x = x | 0x80 ;  // 10xxxxxx
+            bb.put((byte)x) ;
         }
     }
 

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=1225956&r1=1225955&r2=1225956&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
Fri Dec 30 22:46:28 2011
@@ -52,6 +52,8 @@ import org.openjena.atlas.logging.Log ;
 
 public final class BufferingWriter extends Writer
 {
+    // ***** Suspiciously slow.
+    
     private static Logger log = LoggerFactory.getLogger(BufferingWriter.class) ;
     
     // Opposite of PeekReader. 
@@ -142,7 +144,8 @@ public final class BufferingWriter exten
         // This always sets "end of input" in the encoder which is
         // fine if we assume no spanning char sequnces across strings or other
         // units written to this writer.
-        Bytes.toByteBuffer(string, buffer, encoder) ;
+        BlockUTF8.fromChars(string, buffer) ;
+        //Bytes.toByteBuffer(string, buffer, encoder) ;
     }
 
     private int bufferSize()

Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/io/IndentedWriter.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/io/IndentedWriter.java?rev=1225956&r1=1225955&r2=1225956&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/io/IndentedWriter.java
(original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/io/IndentedWriter.java
Fri Dec 30 22:46:28 2011
@@ -68,6 +68,7 @@ public class IndentedWriter
     
     private static Writer makeWriter(OutputStream out)
     {
+        // return BufferingWriter.create(out) ; 
         // Create a writer for the output.
         Writer w = new OutputStreamWriter(out, Chars.createEncoder()) ;
         w =  new BufferedWriter(w, 8*1024) ;

Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/lib/Bytes.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/lib/Bytes.java?rev=1225956&r1=1225955&r2=1225956&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/lib/Bytes.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/lib/Bytes.java Fri Dec
30 22:46:28 2011
@@ -264,12 +264,14 @@ public class Bytes
     }
 
     /** Encode a string into a ByteBuffer : on return position is the end of the encoding
*/
-    public static int toByteBuffer(CharSequence s, ByteBuffer bb)
+    public static void toByteBuffer(CharSequence s, ByteBuffer bb)
     {
+        //BlockUTF8.fromChars(s, bb) ;
+        // To be removed (Dec 2011)
         CharsetEncoder enc = Chars.allocEncoder();
         int x = toByteBuffer(s, bb, enc) ;
         Chars.deallocEncoder(enc) ;
-        return x ;
+        //return x ;
     }
     
     /** Encode a string into a ByteBuffer : on return position is the end of the encoding
*/
@@ -293,6 +295,8 @@ public class Bytes
     /** Decode a string into a ByteBuffer */
     public static String fromByteBuffer(ByteBuffer bb)
     {
+        //return BlockUTF8.toString(bb) ;
+        // To be removed (Dec 2011)
         CharsetDecoder dec = Chars.allocDecoder();
         String x = fromByteBuffer(bb, dec) ;
         Chars.deallocDecoder(dec) ;

Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/system/JenaWriterBase.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/system/JenaWriterBase.java?rev=1225956&r1=1225955&r2=1225956&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/system/JenaWriterBase.java
(original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/system/JenaWriterBase.java
Fri Dec 30 22:46:28 2011
@@ -18,12 +18,14 @@
 
 package org.openjena.riot.system;
 
+import java.io.BufferedWriter ;
 import java.io.OutputStream ;
+import java.io.OutputStreamWriter ;
 import java.io.Writer ;
 import java.util.HashMap ;
 import java.util.Map ;
 
-import org.openjena.atlas.io.BufferingWriter ;
+import org.openjena.atlas.lib.Chars ;
 import org.openjena.atlas.logging.Log ;
 
 import com.hp.hpl.jena.graph.Graph ;
@@ -77,9 +79,10 @@ public abstract class JenaWriterBase imp
     @Override
     public void write(Model model, OutputStream out, String base)
     {
-        BufferingWriter buff = BufferingWriter.create(out, 1023) ;
-        write(model.getGraph(), buff, base) ;
-        buff.flush() ;
+        Writer w = new OutputStreamWriter(out, Chars.createEncoder()) ;
+        w =  new BufferedWriter(w, 8*1024) ;
+        write(model.getGraph(), w, base) ;
+        try { w.flush() ; } catch (Exception e) {}
     }
 
     protected abstract void write(Graph graph, Writer out, String base) ;  



Mime
View raw message