cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with Pound symbol (u00A3)

sid-desh
Advisor
Advisor
0 Kudos

Hi,

I am facing this problem for quite time and need your help to resolve this.

I am developing an XI adapter module which is an EJB. The data coming inside module are rows of data separated by newline with each row separated by comma. basically a CSV file.

I get the data in form of an byte array and then i create a string out of the byte array using String str = new String(byte[]).

I then split the string at newline and continue further processing.

My problem is that when the data contains special characters like pound symbol(£) it is not getting converted into the String in the correct manner. I always end up with Junk characters instead of pound symbol.

I also used the syntax String str = new String(byte[], String charset) with charset = "UTF-8". However this also does not work.

if i remove the EJB module the data is coming in XI properly hence there is some problem when i convert the byte array to String.

Please let me know your suggestions.

Regards

Sidharth

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Siddharth,

There might not be any problem with the conversion. the place where you see your output may also count.

check writing your output to a file and see if that is written properly in a file.

regards,

P.Venkataramanan

sid-desh
Advisor
Advisor
0 Kudos

Hi venkat,

I am creating a file and trying to view the data there itself. The output is not proper. I also posted an idoc with that data yet i ad some junk data only.

Regards

Sidharth

Former Member
0 Kudos

Hi sidharth,

Then there should be some problem with your Byte Array only. So try checking your Byte array, character by character. (i.e) since the byte array is in UNICODE format, take two consecutive bytes convert to string and check where the junk value is printed.

this might be done by code like this

byte[] b1=new byte[2];

for(int i=0;i<b.length;i=i+2)

{

b1[0]=b<i>;

b1[1]=b[i+1];

String s = new String(b1);

System.out.println(s);

}

where b is the original byte array.

moreover the difference between String s = new String(byte[]) and byte[].toString is that,

the first one takes the content of byte array and converts that to a string.

the second one converts the byte array object to a String form. the output of the byte[].toString will be the following info...

getClass().getName() + '@' + Integer.toHexString(hashCode())

for example "[B@cac268"

after @ its the hexadecimal representation of Hashcode value..

regards,

P.Venkataramanan

Answers (2)

Answers (2)

detlev_beutner
Active Contributor
0 Kudos

Hi,

have the answers been of any value for you? If yes, please consider rewarding points for helpful answers! Thanks in avance!

Best regards

Detlev

Former Member
0 Kudos

Have you tried encoding 1208 ?

You really need to look at the stream and find out in which code page the hex value represents the pound sign. This is the encoding you would have to apply.

But be careful, notepad and wordpad do not conform to those encodings and in these tools you may well see a representation for a non displayable character.

Enjoy

Message was edited by: F.J. Brandelik

You might want to wrap your text with an xml header, adding the encoding and display in a browser instead of

notepad as this might display correctly

detlev_beutner
Active Contributor
0 Kudos

Hi Sidharth,

more or less obviously (at least I can hardly think of an alternative), the bytes you get are not a coded with UTF-8. Check how the bytestream is created. If you cannot (have no view on the sources), try different "reasonable" encodings...

Another question: When you watch your converted data - does the "watch-tool" use UTF-8?!

Hope it helps

Detlev

sid-desh
Advisor
Advisor
0 Kudos

Hi Detlev,

I am not able to watch data (like during debugging) as it in an adapter module. What i do is that i just dump the data in a .txt file and when open it with notepad or wordpad i get these junk characters in place pound symbol.

Is there a way i can fin out the encoding of byte array. Creation of byte stream is not in my control as it is being passed to me by the adapter framework.

Also can please tell me the difference between String str = new String(byte[]) and String str = byte[].toString()

Regards

Sidharth

detlev_beutner
Active Contributor
0 Kudos

Hi Sidharth,

> Is there a way i can fin out the encoding of byte array

Normally not. Maybe there are tools which check if parsing a text using a certain encoding makes "sense" or not, but I don't know of such.

> me the difference between String str =

> new String(byte[]) and String str = byte[].toString()

The last one calls toString on the array object and has no conversional function.

Hope it helps

Detlev