Hi,
I'm a bit confused about Internationalization of servlets (and
Internationalization in general).
Specifically I can't see the difference between the following:
1st senario
read in an array of bytes from a byte stream and then store them as a string
using the String(byte[]) constructor.
2nd senario
read in a string from a character stream.
According to the jdk API and some test code I've written, these two senario's
seem to be
equivilant. Here's my understanding of what would happen:
1st senario
the String constructor would using the default encoding of the platform (i.e.
the "file.encoding"
System property) to interpret the bytes read from the byte stream. So, for
example, say the
default encoding of the platform was Japanese, then the bytes would be
interpreted as
Japanese characters. Since Strings and chars are stored by the VM using the
Unicode charset,
the Unicode charset would be used to determine the bytes that correspond to
these characters
and then these bytes would be stored in memory.
summary: bytes from stream -[default platform enc]-> some character -[Unicode
enc]-> bytes to be store in memory
2nd senario
The character stream would read the bytes from the source and interpret which
characters
they correspond to using the default encoding of the platform. Once the
characters are
determined these characters would be returned as a java string (which is stored
in memory as bytes using Unicode byte-char mapping).
Here's a concrete example of what I'm talking about:
1st senario (reading the contents of a file into a stringbuffer)
StringBuffer s = new StringBuffer();
byte[] byteBuffer = new byte[1024];
int bytesRead = 0;
FileInputStream f = new FileInputStream("path to some file");
while( (bytesRead = f.read(byteBuffer,0,byteBuffer.length)) > 0 )
{
s.append(new String(byteBuffer, 0, bytesRead));
}
2st senario (reading the contents of a file into a stringbuffer)
StringBuffer s = new StringBuffer();
char[] charBuffer = new char[1024];
int charsRead = 0;
FileReader f = new FileReader("path to some file");
while( (charsRead = f.read(charBuffer,0,charBuffer.length)) > 0 )
{
s.append(new String(charBuffer, 0, charsRead));
}
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html