Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-15-2008, 01:22 AM
Member
 
Join Date: Apr 2008
Posts: 1
nm123 is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Missing text encoding talgreen Eclipse 0 03-30-2008 09:14 PM
Xml Parse throws SaxParseException. Encoding is UTF-8 insteadof ISO-8859-1 ? j_kathiresan XML 1 03-28-2008 06:08 PM
How to send email with specific Content-Transfer-Encoding? ally Advanced Java 0 02-08-2008 07:14 PM
How to convert the encoding of a file valery New To Java 1 08-06-2007 04:48 AM


All times are GMT +3. The time now is 08:13 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org