Write Socket Output with extend ASCII

P

pcouas

Hi,

I want send datas by socket, but my ASCII value upper than 128 are
truncated, do you have an idea ?
I could not use JDK 1.4 or higher, because this customer has an AIX
4.3.3 .

Thanks
Philippe



Socket socket = new Socket(server, port);
PrintWriter output = new
PrintWriter(socket.getOutputSt­ream(),true);
temp=new String("");
temp=temp.concat(String.valueO­f((char)0x200)); //Pb Here
temp=temp.concat(query); //OK
output.print(temp);
output.print((char)0x200); // Pb Here
output.flush();
 
C

Cantankerous Old Git

pcouas said:
Hi,

I want send datas by socket, but my ASCII value upper than 128 are
truncated, do you have an idea ?
I could not use JDK 1.4 or higher, because this customer has an AIX
4.3.3 .

Thanks
Philippe



Socket socket = new Socket(server, port);
PrintWriter output = new
PrintWriter(socket.getOutputSt­ream(),true);
temp=new String("");
temp=temp.concat(String.valueO­f((char)0x200)); //Pb Here
temp=temp.concat(query); //OK
output.print(temp);
output.print((char)0x200); // Pb Here
output.flush();

PrintWriter uses the platform's defaut character encoding when
converting from text to byte stream. From this code snippet,
there is no clue whatsoever as to what character encoding scheme
the network bytes will be in - on an AS/400 it may well come out
in EBCDIC.

I suggest that you use an OutputStream Writer, and specify the
character encoding scheme in the constructor. You can wrap this
in a PrintWriter if needed. Using a BufferedOutputStream round
the OutputStream may improve performance, while you're at it.

e.g.:
Socket socket = new Socket(server, port);
OutputStream os = Socket.getOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(os);
OutputStreamWriter osw = new OutputStreamWriter(bos,
"ISO8859_1");
PrintWriter output = new PrintWriter(osw);

If you specify ASCII as the output bytestream format, it will (as
it should) convert all character codes above 127 to '?'. There is
no such standard as "extended ASCII". You need to be specific as
to the byte coding used. This may involve asking the pre-existing
application you're trying to talk to what encoding it expects.

The Cog
 
R

Roedy Green

PrintWriter uses the platform's defaut character encoding when
converting from text to byte stream.

// how to determine the default encoding

// in JDK 1.5+
String defaultEncodingName = Charset.defaultCharset().name();

// in JDK 1.4, defaultEncoding will typically be Cp1252
String defaultEncoding = System.getProperty( "file.encoding" );

// canonicalName will be typically be windows-1252
String canonicalName = Charset.forName( defaultEncoding ).name();
 
P

pcouas

Thanks, that's good
Philippe

PS
I could not use JDK 1.4 and JDK 1.5, because customer has an AIX 4.3.3
with only JDK 1.3.1
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top