0

I have used com.sun.org.apache.xerces.internal.impl.dv.util.Base64 package for the purpose of encoding decoding of strings. But I want to use java.* package for encoding and decoding instead of com.sun.apache.* package.

Can you please suggest an appropriate java.* package?

Michaël
  • 3,679
  • 7
  • 39
  • 64
thilinistg
  • 407
  • 3
  • 8
  • 18

3 Answers3

3

If you can wait until Java 8 is released - there will be a java.util.Base64 class. In the meantime you should use the solution from Joachim Sauer's comment. (See Decode Base64 data in Java - second answer)

Community
  • 1
  • 1
mschenk74
  • 3,561
  • 1
  • 21
  • 34
0

Use the java Packages:

java.net.URLDecoder

java.net.URLEncoder

And use it like this:

public static String decodeString(final String string) {
        try {
            return URLDecoder.decode(string, "UTF-8");
        } catch (final UnsupportedEncodingException e) {
            TLog.d(LOG, "Decoding Not Supported");
        }

        return string;
    }
Nargis
  • 4,687
  • 1
  • 28
  • 45
-4

What you mean? You want to use:

import java.*;

instead of using:

import com.sun.apache.*;

?

Seems a lit bit hard. I have one way to do this:

  1. Download the source code of com.sun.org.apache.xerces.internal.impl.dv.util.Base64 packege.
  2. Update the package name.
  3. Re-package the source code.
  4. Import the jar file again.

I don't think you should do this, it might be some license issue.

Howard
  • 4,474
  • 6
  • 29
  • 42
  • 1
    He means he wants to stop using the incorrect, non-portable, unsupported, fragile approach he's currently using in favor of something that is correct and robust. – jahroy Jul 18 '13 at 06:08
  • Haha, Thanks for explanation. I made it wrong! – Howard Jul 18 '13 at 06:19
  • You're welcome... Though I didn't really give much explanation ;-) Here's a [question](http://stackoverflow.com/q/1834826/778118) that does. I particularly like [this answer](http://stackoverflow.com/a/1835670/778118). – jahroy Jul 18 '13 at 06:23