Results 1 to 1 of 1
Thread: Some help with encoding...
- 04-15-2008, 12:22 AM #1
Member
- Join Date
- Apr 2008
- Posts
- 1
- Rep Power
- 0
Some help with encoding...
Hello,
I need to write a byte stream onto the network, what i plan to do is take the byte arrays i have, convert them to a string and recreate the byte array using the string i receive on the other end.
Let me illustrate my problem...
1. bss is what i wish to transfer
byte bss[] = new byte[1];
bss[0] = (byte) (129 & 0xff);
System.out.println("Byte value: " + bss[0]);
System.out.println("Int value: " + ( bss[0] & 0xff ));
2. convert bss to a string
StringBuffer ston = new StringBuffer();
ston.append(new String(bss,"UTF-8"));
3. Recreate bss from string
System.out.println(ston.toString());
byte bss2[] = ston.toString().getBytes();
System.out.println("Byte value: " + bss2[0]);
System.out.println("Int value: " + ( bss2[0] & 0xff ));
For some reason my output is:-
Byte value: -127
Int value: 129
?
Byte value: 63
Int value: 63
I need the same byte value and int value after recreating the bytes using getBytes(), i think there is some issue with the encoding issues coming up, wondering if anyone knows a fix for what i'm trying to do..
Thanks
Neville
Similar Threads
-
How to send email with specific Content-Transfer-Encoding?
By ally in forum Advanced JavaReplies: 1Last Post: 09-27-2008, 01:42 AM -
Missing text encoding
By talgreen in forum EclipseReplies: 0Last Post: 03-30-2008, 08:14 PM -
Xml Parse throws SaxParseException. Encoding is UTF-8 insteadof ISO-8859-1 ?
By j_kathiresan in forum XMLReplies: 1Last Post: 03-28-2008, 05:08 PM -
How to convert the encoding of a file
By valery in forum New To JavaReplies: 1Last Post: 08-06-2007, 03:48 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks