All I need is convert byte[] to String. Then do something with that string and convert back to byte[] array. But in this testing I'm just convert byte[] to string and convert back to byte[] and the result is different.
to convert byte[] to string by using this:
byte[] byteEntity = EntityUtils.toByteArray(entity);
String s = new String(byteEntity,"UTF-8");
Then i tried:
byte[] byteTest = s.getBytes("UTF-8");
Then i complared it:
if (byteEntity.equals(byteTest) Log.i("test","equal");
else Log.i("test","diff");
So the result is different.
I searched in stackoverflow about this but it doesn't match my case. The point is my data is .png picture so the string converted is unreadable. Thanks in advance.
Array.equals
which isn't doing what you think it's doing. Have you tried converting back toStrings
and comparing those values? – David O'Meara May 8 '12 at 7:02response = httppost.execute()
->entity = response.getEntity
->byte[] byteEntity = EntityUtils.toByteArray(entity)
then i have to convert this byte[] to string then xor with key for decryption (Actually i tried to make decryption that not convert to string, but unfortunately it's not work.) after that i have to convert it to byte[] again to make it as ByteArrayOutputStream if you have any idea about the better method, very appreciate. – majorl3oat May 9 '12 at 1:03