[kaffe] CVS kaffe (dalibor): Reverted EncodingManager changes

Kaffe CVS cvs-commits at kaffe.org
Tue Jul 27 09:08:33 PDT 2004


PatchSet 5023 
Date: 2004/07/27 15:58:04
Author: dalibor
Branch: HEAD
Tag: (none) 
Log:
Reverted EncodingManager changes

2004-07-26  Dalibor Topic  <robilad at kaffe.org>

        * libraries/javalib/gnu/java/io/EncodingManager.java:
        Reverted back to old version to fix unintended commit.
        Brown paper bag time.

        Reported by: Guilhem Lavaux <guilhem at kaffe.org>

Members: 
	ChangeLog:1.2581->1.2582 
	libraries/javalib/gnu/java/io/EncodingManager.java:1.4->1.5 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2581 kaffe/ChangeLog:1.2582
--- kaffe/ChangeLog:1.2581	Tue Jul 27 15:29:45 2004
+++ kaffe/ChangeLog	Tue Jul 27 15:58:04 2004
@@ -1,3 +1,11 @@
+2004-07-26  Dalibor Topic  <robilad at kaffe.org>
+
+	* libraries/javalib/gnu/java/io/EncodingManager.java:
+	Reverted back to old version to fix unintended commit.
+	Brown paper bag time.
+
+	Reported by: Guilhem Lavaux <guilhem at kaffe.org>
+
 2004-07-27  Helmer Kraemer  <hkraemer at freenet.de>
 
 	* test/internal/jit_stub.c (main): GC_init has become KGC_init
Index: kaffe/libraries/javalib/gnu/java/io/EncodingManager.java
diff -u kaffe/libraries/javalib/gnu/java/io/EncodingManager.java:1.4 kaffe/libraries/javalib/gnu/java/io/EncodingManager.java:1.5
--- kaffe/libraries/javalib/gnu/java/io/EncodingManager.java:1.4	Mon Jul 26 21:13:49 2004
+++ kaffe/libraries/javalib/gnu/java/io/EncodingManager.java	Tue Jul 27 15:58:06 2004
@@ -38,17 +38,17 @@
 
 package gnu.java.io;
 
-import java.lang.reflect.Constructor;
+import gnu.java.io.decode.Decoder;
+import gnu.java.io.decode.KaffeDecoder;
+import gnu.java.io.encode.Encoder;
+import gnu.java.io.encode.KaffeEncoder;
+
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
 import java.util.Hashtable;
-import java.util.StringTokenizer;
-import gnu.java.io.decode.Decoder;
-import gnu.java.io.encode.Encoder;
-
 
-import java.io.FileOutputStream;
+// gnu.java.io.EncodingManager that works with kaffe
 
 /**
   * This class is used to create new instances of Decoders for a specified
@@ -57,7 +57,8 @@
   *
   * @version 0.0
   *
-  * @author Aaron M. Renn (arenn at urbanophile.com)
+  * @author Aaron M. Renn (arenn at urbanophile.com),
+  * Ito Kazumitsu (kaz at maczuka.gcd.org)
   */
 public class EncodingManager
 {
@@ -69,24 +70,9 @@
  */
 
 /**
-  * This is the encoding class search path
-  */
-private static String encoding_path;
-
-/**
   * This is the system default character encoding
   */
-private static String default_encoding;
-
-/**
-  * This is the <code>Constructor</code> for the default <code>Decoder</code>
-  */
-private static Constructor default_decoder_cons;
-
-/**
-  * This is the <code>Constructor</code> for the default <code>Encoder</code>
-  */
-private static Constructor default_encoder_cons;
+private static String default_encoding = "Default";
 
 /**
   * This is the default instance of the default <code>Decoder</code>, put
@@ -101,68 +87,42 @@
 private static Encoder default_encoder_instance;
 
 /**
-  * This is our hash table of previously loaded <code>Decoder</code> classes
-  */
-private static Hashtable decoder_cons;
-
-/**
   * This is hash table of cached instances of <code>Decoder</code> objects
   */
 private static Hashtable decoder_instances;
 
 /**
-  * This is our hash table of previously loaded <code>Encoder</code> classes
-  */
-private static Hashtable encoder_cons;
-
-/**
   * This is hash table of cached instances of <code>Encoder</code> objects
   */
 private static Hashtable encoder_instances;
 
 
+/*
 static 
 {
   // Initialize hashtables
-  decoder_cons = new Hashtable();
-  encoder_cons = new Hashtable();
   decoder_instances = new Hashtable();
   encoder_instances = new Hashtable();
 
-  // Find the system default decoder search path
-  encoding_path = System.getProperty("file.encoding.pkg");
-  if (encoding_path == null)
-    encoding_path = "gnu.java.io";
-  else
-    encoding_path = encoding_path + ":gnu.java.io";
-
   // Find the system default encoding name
-  String default_encoding = System.getProperty("file.encoding","8859_1");
+  // String default_encoding = System.getProperty("file.encoding","8859_1");
+  // I am not sure whether System has already been initialized.
+  String default_encoding = "Default";
 
   // Load the class
   try
     {
       // First the Decoder side
-      default_decoder_cons = findDecoderConstructor(default_encoding, true);
-
-      Object[] objs = new Object[1];
-      objs[0] = null;
 
       default_decoder_instance = 
-            (Decoder)default_decoder_cons.newInstance(objs);
+            new KaffeDecoder(null, default_encoding);
         
       // Now the Encoder side
-      default_encoder_cons = findEncoderConstructor(default_encoding, true);
-
-      objs = new Object[1];
-      objs[0] = null;
 
       default_encoder_instance = 
-            (Encoder)default_encoder_cons.newInstance(objs);
+            new KaffeEncoder(null, default_encoding);
         
       // Add items to the hashtable;
-      decoder_cons.put(default_encoding, default_decoder_cons);
-      encoder_cons.put(default_encoding, default_encoder_cons);
       decoder_instances.put(default_encoding, default_decoder_instance);
       encoder_instances.put(default_encoding, default_encoder_instance);
     }
@@ -171,7 +131,8 @@
       throw new Error("Cannot load system default encoding '" + 
                      default_encoding + "': " + e.getMessage());
     }
-}  
+}
+*/  
 
 /*************************************************************************/
 
@@ -179,90 +140,6 @@
  * Class Methods
  */
 
-/**
-  * This method loads a <code>Decoder</code> class for the given
-  * encoding name.
-  *
-  * @exception UnsupportedEncodingException If a <code>Decoder</code> for this encoding cannot be found.
-  */
-private static Constructor
-findDecoderConstructor(String encoding, boolean cache) 
-                             throws UnsupportedEncodingException
-{
-  // First check for an aliased encoding name
-  String alias = System.getProperty("gnu.java.io.encoding_scheme_alias." + 
-                                    encoding);
-  if (alias != null)
-    encoding = alias;
-
-  StringTokenizer st = new StringTokenizer(encoding_path, ":");
-
-  while (st.hasMoreTokens())
-    {
-      String classname = st.nextToken() + ".decode.Decoder" + encoding;
-      try
-        {
-          Class cls = Class.forName(classname);
-
-          Class[] params = new Class[1];
-          params[0] = InputStream.class;
-
-          Constructor cons = cls.getConstructor(params);
-
-          if (cache)
-            decoder_cons.put(encoding, cons);            
-
-          return(cons);
-        }
-      catch(Exception e) { ; }
-    }
-
-  throw new UnsupportedEncodingException(encoding);
-}
-       
-/*************************************************************************/
-
-/**
-  * This method loads an <code>Encoder</code> class for the given
-  * encoding name.
-  *
-  * @exception UnsupportedEncodingException If a <code>Encoder</code> for this encoding cannot be found.
-  */
-private static Constructor
-findEncoderConstructor(String encoding, boolean cache) 
-                             throws UnsupportedEncodingException
-{
-  // First check for an aliased encoding name
-  String alias = System.getProperty("gnu.java.io.encoding_scheme_alias." + 
-                                    encoding);
-  if (alias != null)
-    encoding = alias;
-
-  StringTokenizer st = new StringTokenizer(encoding_path, ":");
-
-  while (st.hasMoreTokens())
-    {
-      String classname = st.nextToken() + ".encode.Encoder" + encoding;
-      try
-        {
-          Class cls = Class.forName(classname);
-
-          Class[] params = new Class[1];
-          params[0] = OutputStream.class;
-
-          Constructor cons = cls.getConstructor(params);
-
-          if (cache)
-            encoder_cons.put(encoding, cons);            
-
-          return(cons);
-        }
-      catch(Exception e) { ; }
-    }
-
-  throw new UnsupportedEncodingException(encoding);
-}
-       
 /*************************************************************************/
 
 /**
@@ -274,9 +151,11 @@
   * @return An instance of the default <code>Decoder</code>.
   */
 public static Decoder
-getDecoder()
+getDecoder() throws UnsupportedEncodingException
 {
-  return(default_decoder_instance);
+  // return(default_decoder_instance);
+  // return(new KaffeDecoder(null, default_encoding));
+  return(new KaffeDecoder(null, "Default"));
 }
 
 /*************************************************************************/
@@ -323,6 +202,7 @@
 public static Decoder
 getDecoder(String encoding, boolean cache) throws UnsupportedEncodingException
 {
+  if (decoder_instances == null) decoder_instances = new Hashtable();
   Decoder dec = (Decoder)decoder_instances.get(encoding);
   if (dec != null)
     return(dec);
@@ -347,20 +227,15 @@
 public static Decoder
 getDecoder(InputStream in)
 {
-  Object[] params = new Object[1];
-  params[0] = in;
-
-  Decoder dec = null;
   try
     {
-      dec = (Decoder)default_decoder_cons.newInstance(params);
+      // return(getDecoder(in, default_encoding, false));
+      return(getDecoder(in, "Default", false));
     }
   catch(Exception e)
     {
       throw new Error("Unexpected problems with default decoder");
     }
-
-  return(dec);
 }
 
 /*************************************************************************/
@@ -394,7 +269,7 @@
   *
   * @param in The <code>InputStream</code> to read from
   * @param encoding The name of the character encoding scheme to use
-  * @param cache <code>true</code> to cache the returned <code>Decoder</code>, <code>false</code> otherwise.
+  * @param cache <code>true</code> to cache the returned <code>Decoder</code>, <code>false</code> otherwise.  Actually, not used.
   *
   * @exception UnsupportedEncodingException If a <code>Decoder</code> for this encoding cannot be found
   */
@@ -402,14 +277,10 @@
 getDecoder(InputStream in, String encoding, boolean cache) 
                               throws UnsupportedEncodingException
 {
-  Constructor cons = findDecoderConstructor(encoding, cache);
-  Object[] params = new Object[1];
-  params[0] = in;
-
   Decoder dec = null;
   try
     {
-      dec = (Decoder)cons.newInstance(params); 
+      dec = new KaffeDecoder(in, encoding);
     }
   catch(Exception e)
     {
@@ -432,7 +303,8 @@
 public static Encoder
 getEncoder()
 {
-  return(default_encoder_instance);
+  // return(default_encoder_instance);
+  return(new KaffeEncoder(null, "Default"));
 }
 
 /*************************************************************************/
@@ -479,6 +351,7 @@
 public static Encoder
 getEncoder(String encoding, boolean cache) throws UnsupportedEncodingException
 {
+  if (encoder_instances == null) encoder_instances = new Hashtable();
   Encoder enc = (Encoder)encoder_instances.get(encoding);
   if (enc != null)
     return(enc);
@@ -503,17 +376,15 @@
 public static Encoder
 getEncoder(OutputStream out)
 {
-  Object[] params = new Object[1];
-  params[0] = out;
-
   Encoder enc = null;
   try
     {
-      enc = (Encoder)default_encoder_cons.newInstance(params);
+      // enc = getEncoder(out, default_encoding, false);
+      enc = getEncoder(out, "Default", false);
     }
   catch(Exception e)
     {
-      throw new Error("Unexpected problems with default decoder");
+      throw new Error("Unexpected problems with default encoder");
     }
 
   return(enc);
@@ -550,7 +421,7 @@
   *
   * @param in The <code>OutputStream</code> to read from
   * @param encoding The name of the character encoding scheme to use
-  * @param cache <code>true</code> to cache the returned <code>Encoder</code>, <code>false</code> otherwise.
+  * @param cache <code>true</code> to cache the returned <code>Encoder</code>, <code>false</code> otherwise. Actually, not used.
   *
   * @exception UnsupportedEncodingException If a <code>Decoder</code> for this encoding cannot be found
   */
@@ -558,14 +429,10 @@
 getEncoder(OutputStream out, String encoding, boolean cache) 
                               throws UnsupportedEncodingException
 {
-  Constructor cons = findEncoderConstructor(encoding, cache);
-  Object[] params = new Object[1];
-  params[0] = out;
-
   Encoder enc = null;
   try
     {
-      enc = (Encoder)cons.newInstance(params); 
+      enc = new KaffeEncoder(out, encoding); 
     }
   catch(Exception e)
     {




More information about the kaffe mailing list