Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
When i try to get the bytestream to write out the bytes using String(responseBytes)

Java
in_ = new DataInputStream(eiscpSocket_.getInputStream());
       byte [] responseBytes = new byte[64] ;
       int numBytesReceived = 0;

       numBytesReceived = in_.read(responseBytes);
       retVal = new String(responseBytes); //new String(responseBytes);
       System.out.println("received " + numBytesReceived + " bytes: \"" + responseBytes +"  "+ retVal + " \"" );


But System.out.println("received " + numBytesReceived + " bytes: \"" + responseBytes +" "+ retVal + " \"" ) does not print anything after retVal and not even the whole retVal.

I Get this output
received 46 bytes: "[B@137c60d  ISCP



using this program to get a response from my onkyo reciever

why cant i print my bytes response?
Posted
Comments
Sergey Alexandrovich Kryukov 31-Jan-12 19:06pm    
What is the content type you are supposed to receive? Your byte array can contain nulls, for example, it could be interpreted as null-terminated string by println...
--SA
Krillezz 1-Feb-12 6:25am    
it will probably contain a few nulls, do i have to iterate throught the bytearray to get my response?

I sending it in hexcode so i guess i should get hex back, but then i expect numbers printed, but i get nothing.
krumia 11-Feb-12 22:55pm    
I don't think the problem is with println.

If you're not really sure, add a loop after the println and print the string byte by byte.

I think the problem is in retrieving the bytes. Do you have a way of checking the data that is sent? and then compare?

Null characters in between others should not be a problem in println as far as I know.
Krillezz 17-Feb-12 17:25pm    
the null characters seemed to be the thing ending it for me, i solved it whit looping the bytes! thanks

1 solution

Looped the bytes and then printed them, solved it for me!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900