Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
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 05-01-2007, 11:04 PM
Member
 
Join Date: Apr 2007
Location: Pennsylvania,USA
Posts: 46
sandor is on a distinguished road
Byte Array
I have a PublicKey object that I haved called getEncoded() on to get its representation as an array of bytes.
I then want to send these to another client so they can use the array of bytes.
InputStreamReader can only read Strings at a time, so I have the right value but in the form of a String.
I need to convert the value I have in my String to bytes. Example:

I print out the array of bytes on the server side, I get:

[B@c79809

I print out the String read on the receiving end, I get:

[B@c79809

It's the same, so I want that exact value in an array of bytes rather than a String. How do I get that?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-01-2007, 11:09 PM
Member
 
Join Date: Apr 2007
Location: USA
Posts: 50
derrickD is on a distinguished road
The subclasses of Reader are meant for character streams.

To read bytes, look at BufferedInputStream.

Just a reminder that what you see in "[B@c79809" is a string representation of a byte array; the "[B" part signifies that it's a byte array
(as opposed to, say, an int array), and the "@c79809" part is a representation of the array's address. You may know this already,
but I wanted to make sure you didn't mistake that string for the encoded byte values.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-06-2007, 09:19 AM
Member
 
Join Date: Mar 2007
Posts: 41
peiceonly is on a distinguished road
If the "toString () " method is not implemented we get the values something like this ? So the question is what is the relationship between bytearray and the toString ?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 06-20-2008, 11:16 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 783
Nicholas Jordan is on a distinguished road
Use Base64 encoding, I found one in the libs yesterday and as well have an open source Base64 encoder.

Since we have key material or something, doing toString() and so on is either inefficient, ineffective or insecure for some reason or another. The proof of concept is that any and all pro's use Base64 encoding for transmission of binary - that is what it was designed for and would not have been written unless there was a need for it.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 06-20-2008, 11:40 PM
fishtoprecords's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 475
fishtoprecords is on a distinguished road
Free open source code for this at my website, pfarrell.com
look in the /java subdirectory
Technical Notes
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 08-28-2008, 08:45 PM
ProjectKaiser's Avatar
Member
 
Join Date: Aug 2008
Location: Saint-Petersburg, Russia
Posts: 47
ProjectKaiser is on a distinguished road
I think the following code will give your some figures:

byte b1[] = new byte[]{1, 11, 2, 22, 33, 127};
System.out.println(Arrays.toString(b1));

String s = new String(b1, "utf-8");
//System.out.println(s);

byte b2[] = s.getBytes("utf-8");
System.out.println(Arrays.toString(b2));
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 08-28-2008, 09:44 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
Quote:
I have the right value but in the form of a String. .
How did you convert the byte[] to String? That will determine how to
Quote:
convert the value I have in my String to bytes
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 08-28-2008, 11:29 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 783
Nicholas Jordan is on a distinguished road
base64 v DataOutputStream
There is a missing element here of how it is that original poster is stuck with going through a string, I noticed in ftr's comments in the base64 encoder something to the effect of may not be reversable. As Norm states, it is how opie converts in the first place that matters for getting data back to bin - hex - octets but going through String method seems to introduce indefinite risks surrounding contemporary String ( ususaly viewed as human-readable or at least containing few if any nulls ) vis-a-vis byte / binary data transmission. Those are distinguishable problem domains.

{Norm, I got a couple of 500-800 page Java books back from my bench tech, let me know if you want me to ship them to you as they are not being used by me any more.}
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 08-29-2008, 02:28 PM
ProjectKaiser's Avatar
Member
 
Join Date: Aug 2008
Location: Saint-Petersburg, Russia
Posts: 47
ProjectKaiser is on a distinguished road
I agree that going though String is potentially dangerous, but...There is no Base64 encoder/decoder in the standard Java SDK class library !

There is Sun specific sun.misc.BASE64Encoder, but it is undocumented and generally can not be used.

You can use things like this:
Base64: Public Domain Base64 Encoder/Decoder

Last edited by ProjectKaiser : 08-29-2008 at 04:59 PM.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 11-16-2008, 01:15 PM
Member
 
Join Date: Nov 2008
Posts: 5
kHim is on a distinguished road
heLLo,,!!
cAn u pLeAse give mE tHE cOde of tHis oUtpUt?
using aRRay

@
@@
@ @
@@@@
@ @
@@ @@
@ @ @ @
@@@@@@@@
@ @
@@ @@
@ @ @ @
@@@@ @@@@
@ @ @ @
@@ @@ @@ @@
@ @ @ @ @ @ @ @
@@@@@@@@@@@@@@@@
@ @
@@ @@
@ @ @ @
@@@@ @@@@
@ @ @ @
@@ @@ @@ @@
@ @ @ @ @ @ @ @
@@@@@@@@ @@@@@@@@
@ @ @ @
@@ @@ @@ @@
@ @ @ @ @ @ @ @
@@@@ @@@@ @@@@ @@@@
@ @ @ @ @ @ @ @
@@ @@ @@ @@ @@ @@ @@ @@
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 11-16-2008, 01:19 PM
Member
 
Join Date: Nov 2008
Posts: 5
kHim is on a distinguished road
arrays
heLLo,,!!
cAn u pLeAse give mE tHE cOde of tHis oUtpUt using two dimensional array?
thAnks a lot

@
@@
@ @
@@@@
@ @
@@ @@
@ @ @ @
@@@@@@@@
@ @
@@ @@
@ @ @ @
@@@@ @@@@
@ @ @ @
@@ @@ @@ @@
@ @ @ @ @ @ @ @
@@@@@@@@@@@@@@@@
@ @
@@ @@
@ @ @ @
@@@@ @@@@
@ @ @ @
@@ @@ @@ @@
@ @ @ @ @ @ @ @
@@@@@@@@ @@@@@@@@
@ @ @ @
@@ @@ @@ @@
@ @ @ @ @ @ @ @
@@@@ @@@@ @@@@ @@@@
@ @ @ @ @ @ @ @
@@ @@ @@ @@ @@ @@ @@ @@
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
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
Byte Values javaplus New To Java 1 06-23-2008 02:08 AM
using Byte arrays mew New To Java 2 01-30-2008 05:54 AM
BufferedImage to Byte Java Tip Java Tips 0 01-22-2008 10:17 PM
Reading/Writing a File using byte array Java Tip Java Tips 0 01-16-2008 12:41 PM
int to byte ravian New To Java 1 01-13-2008 09:22 PM


All times are GMT +3. The time now is 10:24 AM.


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