String.getBytes wierdness

S

Scott.R.Lemke

I'm playing around with some of the digesting classes to see if I can't
write a quick file comparer(diff) utility for practice. What I am doing
is taking a string, digesting it, then comparing it to a digest to
another string to see if they are equal(trying to use something along
the lines of the rsync algorithm)

What I came across was that calling getBytes on my strings is not
giving me a consistent result. Successive getByte calls to equivilent,
or even the same, string object are giving me different bytes, which in
turn leads to different digests.

My question is, am I missing something? Is my assumption that calls of
getBytes to equivilent or the exact same string should give the same
byte[] result wrong?
 
M

Matt Humphrey

I'm playing around with some of the digesting classes to see if I can't
write a quick file comparer(diff) utility for practice. What I am doing
is taking a string, digesting it, then comparing it to a digest to
another string to see if they are equal(trying to use something along
the lines of the rsync algorithm)

What I came across was that calling getBytes on my strings is not
giving me a consistent result. Successive getByte calls to equivilent,
or even the same, string object are giving me different bytes, which in
turn leads to different digests.

My question is, am I missing something? Is my assumption that calls of
getBytes to equivilent or the exact same string should give the same
byte[] result wrong?

I would expect getBytes to give different results on different platforms
because that method uses the default encoding. People using getBytes to
send network messages often find the server and client have different
default encoders. However, I don't see how it would give different results
locally. Whatever getBytes produces must be able to be decoded to the same
source string. Can you post a short code example?

Cheers,
Matt Humphrey (e-mail address removed) http://www.iviz.com/
 
S

Scott.R.Lemke

Matt said:
I'm playing around with some of the digesting classes to see if I can't
write a quick file comparer(diff) utility for practice. What I am doing
is taking a string, digesting it, then comparing it to a digest to
another string to see if they are equal(trying to use something along
the lines of the rsync algorithm)

What I came across was that calling getBytes on my strings is not
giving me a consistent result. Successive getByte calls to equivilent,
or even the same, string object are giving me different bytes, which in
turn leads to different digests.

My question is, am I missing something? Is my assumption that calls of
getBytes to equivilent or the exact same string should give the same
byte[] result wrong?

I would expect getBytes to give different results on different platforms
because that method uses the default encoding. People using getBytes to
send network messages often find the server and client have different
default encoders. However, I don't see how it would give different results
locally. Whatever getBytes produces must be able to be decoded to the same
source string. Can you post a short code example?

Cheers,
Matt Humphrey (e-mail address removed) http://www.iviz.com/

Blah, nevermind, I was looking at memory addresses(knew I should have
listened to my gut). I'm so used to having my print functions know how
to print byte arrays.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top