You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Mulligan, Scott H" <sc...@eds.com> on 2007/05/08 23:29:46 UTC

[OT] Reading Unicode Files

In my Struts application, when I load a Resource Bundle (Property file)
that has Unicode characters (\u1234) they get interpreted as single
characters. However, when I read a file using a FileInputStream the
Unicode characters get interpreted as a String "\u1234".

I know I am missing something basic, but I can not figure it out. Can
anyone please tell me what the Properties.load() method does that I am
not doing?

Thanks for any help you can provide.


Scott M.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] Reading Unicode Files

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Kapil,

Kapil Sharma wrote:
> This code properly reads the unicode files in jsp and set in session

The OP was asking about how to read properties files, which are pretty
much defined to be ISO-8859-1 with escape codes for out-of-charset
characters that look like this:

\u1234

Scott wasn't asking about how to read Unicode files (that's easy: use
set the content type properly)... he was asking about how to properly
read the escape sequences.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGQcEe9CaO5/Lv0PARAtWMAKCTSJp+lzZA8j2kITWbZndacSai/gCghuZo
WR4aijPvcYZbG8jAQhdgR3E=
=fc+X
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: [OT] Reading Unicode Files

Posted by Kapil Sharma <ka...@iap-online.com>.
This code properly reads the unicode files in jsp and set in session


	Properties prop = null;
			if (session.getAttribute("Properties") == null) {
				
				URL myURL = null;
				
				myURL = application.getResource("/common/language/japanese_lang.properties");
				
				
				String fnsKey;
				String fnsVal;
				InputStream is = myURL.openStream();
				BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
				prop = new Properties();
				String fnsData;
				fnsData = in.readLine();
				while (fnsData != null) {
					String fnsRetVal = "";
					StringTokenizer stParse = new StringTokenizer(fnsData, "="); //breaking the string
					while (stParse.hasMoreTokens()) {
						fnsKey = stParse.nextToken().trim();
						if (stParse.hasMoreTokens()) {
							fnsVal = stParse.nextToken().trim();
							prop.setProperty(fnsKey, fnsVal);
						}
					}
					fnsData = in.readLine();
				}
				session.setAttribute("Properties", prop);
			} else {
				prop = (Properties) session.getAttribute("Properties");
			}



Thanks and Regards,
Kapil Sharma 
IAP Company Ltd.


-----Original Message-----
From: Christopher Schultz [mailto:chris@christopherschultz.net]
Sent: Wednesday, May 09, 2007 7:18 AM
To: Struts Users Mailing List
Subject: Re: [OT] Reading Unicode Files


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Scott

Mulligan, Scott H wrote:
> In my Struts application, when I load a Resource Bundle (Property file)
> that has Unicode characters (\u1234) they get interpreted as single
> characters. However, when I read a file using a FileInputStream the
> Unicode characters get interpreted as a String "\u1234".

java.util.Properties.load includes the interpretation of those \uWXYZ
codes, while you are probably not reading them in as such.
(ResourceBundle uses Properties.load or something exactly like it to
load PropertyResourceBundles).

> I know I am missing something basic, but I can not figure it out. Can
> anyone please tell me what the Properties.load() method does that I am
> not doing?

They specifically look for \uWXYZ sequences and do their own conversion.
It's not a character encoding issue or anything like that... it's just
parsing and converting. You'll have to do it yourself.

Don't forget that if you have the JDK installed you can look at the Java
sources for just about any class. Try looking for JAVA_HOME/src.zip or
JAVA_HOME/share/src.zip and looking at the java.util.Properties source
code yourself.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGQPcZ9CaO5/Lv0PARAsZPAKCGHvlQS0kVFTIJeuEexHQbIZ+iyACeKohv
W0kv/TF72AucxxIwNNQlt4s=
=LCf9
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] Reading Unicode Files

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Scott

Mulligan, Scott H wrote:
> In my Struts application, when I load a Resource Bundle (Property file)
> that has Unicode characters (\u1234) they get interpreted as single
> characters. However, when I read a file using a FileInputStream the
> Unicode characters get interpreted as a String "\u1234".

java.util.Properties.load includes the interpretation of those \uWXYZ
codes, while you are probably not reading them in as such.
(ResourceBundle uses Properties.load or something exactly like it to
load PropertyResourceBundles).

> I know I am missing something basic, but I can not figure it out. Can
> anyone please tell me what the Properties.load() method does that I am
> not doing?

They specifically look for \uWXYZ sequences and do their own conversion.
It's not a character encoding issue or anything like that... it's just
parsing and converting. You'll have to do it yourself.

Don't forget that if you have the JDK installed you can look at the Java
sources for just about any class. Try looking for JAVA_HOME/src.zip or
JAVA_HOME/share/src.zip and looking at the java.util.Properties source
code yourself.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGQPcZ9CaO5/Lv0PARAsZPAKCGHvlQS0kVFTIJeuEexHQbIZ+iyACeKohv
W0kv/TF72AucxxIwNNQlt4s=
=LCf9
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org