Euro sign not displayed when transmitted through stream

R

Raga

Hi,

This is what is being done. Euro sign is initialized as a String & then
written through PrintWriter into a custom stream, where it's converted
to type int[]. When this is read in the client end & displayed, it is
getting displayed as a '?'. In short, this is how it is coded:

String string = new String("€");
PrintWriter writer = new PrintWriter(new customOutputStream(), true);
writer.print(string);


In the custom stream, the write() method is defined like this:

public void write(int arg0) throws IOException
{
data[top][j++] = arg0;
}

where data[][] is an 'int' array.

For the string "€", if I print the value of data[][], am getting some
numbers. How do I verify if the numbers that I get corresponding to the
String "€" is correct?

In the client, a method gets data[][] & writes to the screen. Am
getting '?'. If I set the OutputStream's encoding as UTF-8, am getting
3 '?'s. For UTF-16. am getting 2 '?'s. Can someone please throw some
light on this?

Thanks.
 
K

KiLVaiDeN

Raga said:
Hi,

This is what is being done. Euro sign is initialized as a String & then
written through PrintWriter into a custom stream, where it's converted
to type int[]. When this is read in the client end & displayed, it is
getting displayed as a '?'. In short, this is how it is coded:

String string = new String("€");
PrintWriter writer = new PrintWriter(new customOutputStream(), true);
writer.print(string);


In the custom stream, the write() method is defined like this:

public void write(int arg0) throws IOException
{
data[top][j++] = arg0;
}

where data[][] is an 'int' array.

For the string "€", if I print the value of data[][], am getting some
numbers. How do I verify if the numbers that I get corresponding to the
String "€" is correct?

In the client, a method gets data[][] & writes to the screen. Am
getting '?'. If I set the OutputStream's encoding as UTF-8, am getting
3 '?'s. For UTF-16. am getting 2 '?'s. Can someone please throw some
light on this?

Thanks.

Hello,
Have you tried using an OutputStreamWriter ?

Cheers,
K
 
L

Lothar Kimmeringer

Raga said:
In the client, a method gets data[][] & writes to the screen. Am
getting '?'. If I set the OutputStream's encoding as UTF-8, am getting
3 '?'s. For UTF-16. am getting 2 '?'s. Can someone please throw some
light on this?

What's the encoding of the screen (aka console)? It doesn't seem
to be UTF-8 or UTF-16. Is it a windows-system? Then it's AFAIR
cp1252. So you should try something like

out = OutputStreamWriter(System.out, System.getProperty("file.encoding"));
out.write("¤\n");

If you still get '?' your system-encoding is ASCII or Latin1 or
another encoding that doesn't know the euro-sign.


Regards, Lothar
--
Lothar Kimmeringer E-Mail: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
R

Raga

Hi,

Thanks to all for your replies.

1. How do I change my system's default encoding?

2. Another method I tried is to instantiate PrintWriter like this:

OutputStreamWriter outWriter = new OutputStreamWriter(new
DataSEPipedOutputStream(), "UTF-8");
PrinWriter writer = new PrintWriter(outWriter, true);

But this gives '???' on the screen.

If I change that to UTF-16, instead of UTF-8, I get '??' on the screen.

Not sure why this weird behaviour.


Thanks.



Lothar said:
Raga said:
In the client, a method gets data[][] & writes to the screen. Am
getting '?'. If I set the OutputStream's encoding as UTF-8, am getting
3 '?'s. For UTF-16. am getting 2 '?'s. Can someone please throw some
light on this?

What's the encoding of the screen (aka console)? It doesn't seem
to be UTF-8 or UTF-16. Is it a windows-system? Then it's AFAIR
cp1252. So you should try something like

out = OutputStreamWriter(System.out, System.getProperty("file.encoding"));
out.write("¤\n");

If you still get '?' your system-encoding is ASCII or Latin1 or
another encoding that doesn't know the euro-sign.


Regards, Lothar
--
Lothar Kimmeringer E-Mail: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
L

Lothar Kimmeringer

Raga said:
1. How do I change my system's default encoding?

Depends on the system.
2. Another method I tried is to instantiate PrintWriter like this:

OutputStreamWriter outWriter = new OutputStreamWriter(new
DataSEPipedOutputStream(), "UTF-8");
PrinWriter writer = new PrintWriter(outWriter, true);

But this gives '???' on the screen.

If your console expects e.g. Latin-15, you simply don't fit
it the way being expected. You must use the encoding of the
console. It's not OK to just set the encoding in the way you
like.
If I change that to UTF-16, instead of UTF-8, I get '??' on the screen.

That you already said in the original post. My answer is still
the same.


Regards, Lothar
--
Lothar Kimmeringer E-Mail: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
R

Raga

Hi, Thanks for your reply. My system is Microsoft Windows XP. How do I
change its encoding? Can you please help?

Thanks.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top