Isn't the "correct" approach for property files to use native2ascii, the
program, encode the file?
The load() command knows how to encode and decode from the \uxxxx format
that is produced.
> -----Original Message-----
> From: Ilkka Priha [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, May 02, 2001 6:26 PM
> To: [EMAIL PROTECTED]
> Subject: RE: [PATCH] Configuration
>
>
> Now that Velocity has nice encoding support for templates, I
> have a new wish
> on my list. Please, be patient :). In addition to templates,
> property files
> are frequently used for defining certain standard string
> literals in user
> interface screens, like UI Manager skins in Turbine.
> Unfortunately, the
> java.util.Properties class has a hardcoded "8859_1" encoding
> in its load()
> method, which makes it difficult to use property files for
> user interfaces
> of non-latin languages.
>
> As Configuration is already an improvement to Properties,
> it's a perfect
> candidate to be even better and implement a load method that supports
> different character encodings. Below is my proposal for the job.
>
> -- Ilkka
>
>
> --- Configuration.old Wed May 2 20:06:04 2001
> +++ Configuration.new Wed May 2 20:05:15 2001
> @@ -65,6 +65,7 @@
> import java.io.OutputStream;
> import java.io.PrintWriter;
> import java.io.Reader;
> +import java.io.UnsupportedEncodingException;
>
> import java.util.ArrayList;
> import java.util.Enumeration;
> @@ -419,11 +420,42 @@
> * @param input An InputStream.
> * @exception IOException.
> */
> - public synchronized void load(InputStream input)
> + public void load(InputStream input)
> throws IOException
> {
> - PropertiesReader reader =
> - new PropertiesReader(new InputStreamReader(input));
> + load(input,null);
> + }
> +
> + /**
> + * Load the properties from the given input stream
> + * and using the specified encoding.
> + *
> + * @param input An InputStream.
> + * @param enc An encoding.
> + * @exception IOException.
> + */
> + public synchronized void load(InputStream input,
> + String enc)
> + throws IOException
> + {
> + PropertiesReader reader = null;
> + if (enc != null)
> + {
> + try
> + {
> + reader =
> + new PropertiesReader(new
> InputStreamReader(input,enc));
> + }
> + catch (UnsupportedEncodingException e)
> + {
> + // Get one with the default encoding...
> + }
> + }
> + if (reader == null)
> + {
> + reader =
> + new PropertiesReader(new InputStreamReader(input));
> + }
>