[kaffe] CVS kaffe (kaz): libraries/javalib/java/nio/charset/Charset.java (providers):

Kaffe CVS cvs-commits at kaffe.org
Fri Jan 7 09:19:29 PST 2005


PatchSet 5805 
Date: 2005/01/07 16:28:14
Author: kaz
Branch: HEAD
Tag: (none) 
Log:
2005-01-07  Ito Kazumitsu  <kaz at maczuka.gcd.org>

        * libraries/javalib/java/nio/charset/Charset.java (providers):
        New method to make an array of CharsetProviders defined in
        META-INF/services/java.nio.charset.spi.CharsetProvider.
        (charsetForName, availableCharsets): Use the new method providers().

        * libraries/javalib/kaffe/io/ByteToCharConverter.java
        (pendingLength, reset),
        libraries/javalib/kaffe/io/CharToByteConverter.java
        (havePending, pendingLength, reset): New methods to be used
        for subclasses of java.nio.charset.Charset.

Members: 
	ChangeLog:1.3349->1.3350 
	libraries/javalib/java/nio/charset/Charset.java:1.6->1.7 
	libraries/javalib/kaffe/io/ByteToCharConverter.java:1.26->1.27 
	libraries/javalib/kaffe/io/CharToByteConverter.java:1.19->1.20 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.3349 kaffe/ChangeLog:1.3350
--- kaffe/ChangeLog:1.3349	Fri Jan  7 14:09:26 2005
+++ kaffe/ChangeLog	Fri Jan  7 16:28:14 2005
@@ -1,3 +1,16 @@
+2005-01-07  Ito Kazumitsu  <kaz at maczuka.gcd.org>
+
+	* libraries/javalib/java/nio/charset/Charset.java (providers):
+	New method to make an array of CharsetProviders defined in
+	META-INF/services/java.nio.charset.spi.CharsetProvider.
+	(charsetForName, availableCharsets): Use the new method providers().
+
+	* libraries/javalib/kaffe/io/ByteToCharConverter.java
+	(pendingLength, reset),
+	libraries/javalib/kaffe/io/CharToByteConverter.java
+	(havePending, pendingLength, reset): New methods to be used
+	for subclasses of java.nio.charset.Charset.
+
 2005-01-06  Dalibor Topic  <robilad at kaffe.org>
 
 	Resynced with GNU Classpath.
Index: kaffe/libraries/javalib/java/nio/charset/Charset.java
diff -u kaffe/libraries/javalib/java/nio/charset/Charset.java:1.6 kaffe/libraries/javalib/java/nio/charset/Charset.java:1.7
--- kaffe/libraries/javalib/java/nio/charset/Charset.java:1.6	Sun Oct 24 17:20:10 2004
+++ kaffe/libraries/javalib/java/nio/charset/Charset.java	Fri Jan  7 16:28:16 2005
@@ -40,12 +40,17 @@
 
 import gnu.java.nio.charset.Provider;
 
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.URL;
 import java.nio.ByteBuffer;
 import java.nio.CharBuffer;
 import java.nio.charset.spi.CharsetProvider;
 import java.util.Collections;
+import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.LinkedHashSet;
 import java.util.Locale;
 import java.util.Set;
 import java.util.SortedMap;
@@ -137,28 +142,74 @@
   private static Charset charsetForName (String charsetName)
   {
     checkName (charsetName);
-    return provider ().charsetForName (charsetName);
+    Charset cs = null;
+    CharsetProvider[] providers = providers ();
+    for (int i = 0; i < providers.length; i++) {
+        cs = providers[i].charsetForName (charsetName);
+        if (cs != null) break;
+    }
+    return cs;
   }
 
   public static SortedMap availableCharsets ()
   {
     TreeMap charsets = new TreeMap (String.CASE_INSENSITIVE_ORDER);
 
-    for (Iterator i = provider ().charsets (); i.hasNext (); )
+    CharsetProvider[] providers = providers ();
+    for (int j = 0; j < providers.length; j++)
       {
-        Charset cs = (Charset) i.next ();
-        charsets.put (cs.name (), cs);
+        for (Iterator i = providers[j].charsets (); i.hasNext (); )
+          {
+            Charset cs = (Charset) i.next ();
+            charsets.put (cs.name (), cs);
+          }
       }
 
     return Collections.unmodifiableSortedMap (charsets);
   }
 
-  // XXX: we need to support multiple providers, reading them from
-  // java.nio.charset.spi.CharsetProvider in the resource directory
-  // META-INF/services
   private static CharsetProvider provider ()
   {
     return Provider.provider ();
+  }
+
+  // we need to support multiple providers, reading them from
+  // java.nio.charset.spi.CharsetProvider in the resource directory
+  // META-INF/services
+
+  private static CharsetProvider[] providers;
+  private static CharsetProvider[] providers ()
+  {
+    if (providers == null)
+      {
+        try
+          {
+            Enumeration en = ClassLoader.getSystemResources("META-INF/services/java.nio.charset.spi.CharsetProvider");
+            LinkedHashSet set = new LinkedHashSet();
+            set.add(provider ());
+            while (en.hasMoreElements())
+              {
+                BufferedReader rdr = new BufferedReader(new InputStreamReader(
+                    ((URL)(en.nextElement())).openStream()));
+                while (true)
+                  {
+                    String s = rdr.readLine();
+                    if (s == null) break;
+                    CharsetProvider p = (CharsetProvider)(
+                        (Class.forName(s)).newInstance());
+                    set.add(p);
+                  }
+               }
+
+            providers = new CharsetProvider[set.size()];
+            set.toArray(providers);
+          }
+        catch (Exception e)
+          {
+            throw new RuntimeException(e);
+          }
+      }
+    return providers;
   }
 
   public final String name ()
Index: kaffe/libraries/javalib/kaffe/io/ByteToCharConverter.java
diff -u kaffe/libraries/javalib/kaffe/io/ByteToCharConverter.java:1.26 kaffe/libraries/javalib/kaffe/io/ByteToCharConverter.java:1.27
--- kaffe/libraries/javalib/kaffe/io/ByteToCharConverter.java:1.26	Fri Oct 22 15:38:56 2004
+++ kaffe/libraries/javalib/kaffe/io/ByteToCharConverter.java	Fri Jan  7 16:28:16 2005
@@ -89,6 +89,14 @@
 	return blen != 0;
 }
 
+public int pendingLength() {
+	return blen;
+}
+
+public void reset() {
+	blen = 0;
+}
+
 public int withdraw ( byte[] to, int tpos, int tlen ) {
 	int n = (tlen < blen ? tlen : blen);
 
Index: kaffe/libraries/javalib/kaffe/io/CharToByteConverter.java
diff -u kaffe/libraries/javalib/kaffe/io/CharToByteConverter.java:1.19 kaffe/libraries/javalib/kaffe/io/CharToByteConverter.java:1.20
--- kaffe/libraries/javalib/kaffe/io/CharToByteConverter.java:1.19	Fri Oct 22 15:38:56 2004
+++ kaffe/libraries/javalib/kaffe/io/CharToByteConverter.java	Fri Jan  7 16:28:17 2005
@@ -80,6 +80,18 @@
 	}
 }
 
+public boolean havePending() {
+	return blen != 0;
+}
+
+public int pendingLength() {
+	return blen;
+}
+
+public void reset() {
+	blen = 0;
+}
+
 private static CharToByteConverter getConverterInternal(String enc)
 {
 	Class cls = (Class)cache.get(enc);




More information about the kaffe mailing list