classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] RFC: ChannelReader #1


From: Robert Schuster
Subject: [cp-patches] RFC: ChannelReader #1
Date: Mon, 31 Jan 2005 04:51:51 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.7.5) Gecko/20050107

Hi,
this patch brings support for the 1.4 style constructors of InputStreamReader. These are the ones that take an InputStream and a java.nio.charset.Charset[Decoder]. The implementation is easy and depends on the Channels class
which has allows to wrap IO-style classes in NIO-style classes.

However Channels had only a stub implementation for newReader(ReadableByteChannel, CharsetDecoder). I changed that by writing the adapter: gnu.java.nio.ChannelReader .

The quirk for having the new InputStreamReader constructors isn't that interesting. The real value of the ChannelReader is that we can now start porting our own character decoders (gnu.java.io.decoder) to NIO.

Dalibor said that Kaffe has a NIO Charset thats based on iconv. With the ChannelReader we can use that from IO, too.

However. This is only the first version of the patch. Its here for general review. I need to look for corner-cases and exception behavior and polish it up every here and then.

After that I am going to implement ChannelReader's counterpart: The evil ChannelWriter ... if no else is faster :-)

The Changelog for the patch will look like this:
2005-01-31  Robert Schuster  <address@hidden>

       * java/nio/channels/Channels: Added FIXMEs for
       stub method implementation.
       (newReader): Implemented.
       * java/io/InputStreamReader:
       (InputStreamReader(InputStream, Charset)): Implemented.
       (InputStreamReader(InputStream, CharsetDecoder)): Implemented.
       * gnu/java/nio/ChannelReader: New class.

Btw: http://developer.classpath.org/mediation/ClasspathCurrentTopics#head-29147ec4a694664ae99b73085a0922c613f39d64

Has some more details about GNU Classpath's character conversion frameworks and their problems.

cu
Robert
? gnu/java/nio/ChannelReader.java
Index: java/io/InputStreamReader.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/InputStreamReader.java,v
retrieving revision 1.17
diff -u -r1.17 InputStreamReader.java
--- java/io/InputStreamReader.java      11 Oct 2004 09:45:20 -0000      1.17
+++ java/io/InputStreamReader.java      31 Jan 2005 03:31:43 -0000
@@ -38,8 +38,11 @@
 
 package java.io;
 
+import java.nio.channels.Channels;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+
 import gnu.java.io.EncodingManager;
-import gnu.java.io.decode.Decoder;
 
 /**
  * This class reads characters from a byte input stream.   The characters
@@ -92,7 +95,7 @@
    * This is the byte-character decoder class that does the reading and
    * translation of bytes from the underlying stream.
    */
-  private Decoder in;
+  private Reader in;
 
   /**
    * This method initializes a new instance of <code>InputStreamReader</code>
@@ -129,6 +132,14 @@
     this.in = EncodingManager.getDecoder(in, encoding_name);
   }
 
+  public InputStreamReader(InputStream in, Charset charset) {
+    this.in = Channels.newReader(Channels.newChannel(in), 
charset.newDecoder(), -1);
+  }
+
+  public InputStreamReader(InputStream in, CharsetDecoder decoder) {
+    this.in = Channels.newReader(Channels.newChannel(in), decoder, -1);
+  }
+  
   /**
    * This method closes this stream, as well as the underlying 
    * <code>InputStream</code>.
Index: java/nio/channels/Channels.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/channels/Channels.java,v
retrieving revision 1.10
diff -u -r1.10 Channels.java
--- java/nio/channels/Channels.java     12 Jan 2005 10:08:13 -0000      1.10
+++ java/nio/channels/Channels.java     31 Jan 2005 03:31:45 -0000
@@ -38,6 +38,7 @@
 
 package java.nio.channels;
 
+import gnu.java.nio.ChannelReader;
 import gnu.java.nio.InputStreamChannel;
 import gnu.java.nio.OutputStreamChannel;
 
@@ -102,7 +103,9 @@
   public static Reader newReader(ReadableByteChannel ch, CharsetDecoder dec,
                                  int minBufferCap)
   {
-    throw new Error("not implemented");
+    // TODO: find out how 'it' reacts on wrong arguments
+    
+    return new ChannelReader(ch, dec, minBufferCap);
   }
 
   /**
@@ -124,6 +127,7 @@
   public static Writer newWriter(WritableByteChannel ch, CharsetEncoder enc,
                                  int minBufferCap)
   {
+    // FIXME: implement 
java.nio.channels.Channel.newWriter(WritableByteChannel, CharsetEncoder, int) 
     throw new Error("not implemented");
   }
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]