sending ebcdic data

I am trying to send ebcdic data from a unix socket server to an os/390 client. I have tried encoding the data as "Cp1047" and then sending it byte at a time via an OutputStreamWriter created with the default encoding of UTF8. That didn't work. Then, in the following code snippet, I basically am doing the same thing, but also creating the OutputStreamWriter with the encoding parameter of "Cp1047". That failed as well, meaning unreadable data was received on the os/390 side.

Any help/pointers would be greatly appreciated.

Thanks.

Jeff

byte[] b=null;

String encoding ="Cp1047";

try{ b = data.getBytes(encoding);}

catch (UnsupportedEncodingException e){System.out.println("writeData() Encoding error => "+e);}

try

{

out =new OutputStreamWriter(connection.getOutputStream(), encoding);

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

{

out.write(b[cntr]);

}

out.flush();

}

catch (IOException e){System.out.println("writeData() Error writing to socket => "+e);}

}

[1756 byte] By [jpfost_1a] at [2007-11-27 3:06:08]
# 1
There is no need to convert the string to EBCDIC bytes before writing to the Writer. Just write the String and the Writer will do the conversion.Message was edited by: sabre150
sabre150a at 2007-7-12 3:52:15 > top of Java-index,Core,Core APIs...
# 2

Yep. Creating an OutputStreamWriter with "Cp1047" encoding worked. Thank you.

Any idea why encoding the data first, and then sending it via the default OutputStreamWriter failed? In that case, the wtr defaults to UTF8, but I'm sending a byte at a time. I would have thought that would work too.

Anyway, thanks again!

Jeff

jpfosta at 2007-7-12 3:52:16 > top of Java-index,Core,Core APIs...
# 3

> Any idea why encoding the data first, and then

> sending it via the default OutputStreamWriter failed?

The Writer.write(int char) method treats the argument as a UNICODE character so it convert it to EBCDIC but you have already converted it to EBCDIC so it gets converted twice! obviously wrong!

sabre150a at 2007-7-12 3:52:16 > top of Java-index,Core,Core APIs...