CharsetDecoder issue

?

-

Data is read from a server and the byteBuffer is decoded using
Charset.forName("ISO-8859-1").newDecoder().

Am I suppose to know beforehand what charset the incoming data is in?
What if it's a mixture of various charsets? What then?
 
C

Chris Head

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

- - said:
Data is read from a server and the byteBuffer is decoded using
Charset.forName("ISO-8859-1").newDecoder().

Am I suppose to know beforehand what charset the incoming data is in?
What if it's a mixture of various charsets? What then?

Hi,
What server? If it's HTTP, then look at the Content-Type header. Ideally
it will look like this:

Content-Type: text/html; charset=UTF-8

or something similar. If it's your own customized protocol, then it's
completely up to you to decide what to do. You can decide to send the
character set name from server to client somehow, or you can declare
that everything will always use <insert your favourite charset here>. If
it's something like FTP, then it's just like reading a file from your
local computer: there's really no way to know what character set it's in.

On a related note, I wonder if a character set should be a property of
the file which is stored directly in the filesystem (in an inode, or
whatever your filesystem calls it) so that applications can query the
operating system for this information, but that's a bit of a
philosophical discussion the ramifications of which I don't really want
to think about right now.

Of course, if only every single application on the planet was set to use
UTF-8 or UCS-2 as the default (UTF-8 for Western languages, UCS-2 for
Chinese/Japanese/etc) with BOMs and to accept either one, we wouldn't be
having this discussion... I guess maybe that day will come, but it's not
here yet.

Chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32)

iD8DBQFCy3oZgxSrXuMbw1YRAlT8AJ9Pde7roRoyV2g9S3g4uneqeKNuzwCcCXVq
66VuQLoqwNrVohntrBql3sY=
=rRm/
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top