Selon Priti Menon <[EMAIL PROTECTED]>:

Could you try to remove the encoding/decoding part and performing directly:

 String decodedString = new String(s.getBytes());

and to compare the hash codes ?

If this fails, then it would mean the special character is not valid in the
default encoding of your Linux box but valid in the (probably different)
encoding of your Windows box.

The javadoc for the constructor String(byte[]) says:

  The behavior of this constructor when the given bytes are not valid
  in the default charset is unspecified.

In this case, a possible workaround would be to explicitely specify an encoding
for which the special character is valid instead of relying on the default
charset of the system.


Luc

> Hi All,
>
> I am facing a problem with the Base64 encoding class in the commons package.
> i.e. org.apache.commons.codec.binary.Base64
>
> I am trying to encode & decode a string back to its original value. I have
> tried this on windows & linux.
> If you compare the hashcodes of the original string with the new string, it
> returns different values with Linux.
>
> For eg.
> String s = "Matrix ";
> System.out.println("s = " + s.hashCode());
> String s1 = new String(Base64.encodeBase64(s.getBytes()));
> String decodedString = new String(Base64.decodeBase64(s1.getBytes()));
> System.out.println("decodedString = " + decodedString.hashCode());
>
> The output on windows :-
> s = Matrix
> s = -1789003553
> decodedString = -1789003553
>
> The output on linux :-
> s = Matrix?
> s = -1789003553
> decodedString = -1789003650
>
> Has anyone faced this problem before ?
>
> Thanks & Regards,
> Priti
>
> PS. There is a special character in the string after the word 'Matrix'.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to