Base64 - officially?

Hi!Could anybody explain me why Sun don't include Base64 encoding-decoding in an official API?
[109 byte] By [alexey.philimonov] at [2007-9-30 22:16:17]
# 1

I guess if there is a reason it would be that there are an infinite number of possible algorithms, so necessarily they can't all be there. One crowd shouts to Sun's ear "put in the kitchen sink", while the other ear gets an equally loud "keep it simple, and make rt.jar smaller".

There are base64 classes in sun.misc and java.util.prefs, but they aren't public. Google also reveals a number of third party base64 classes.

There is a [url=http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4235519]request for enhancement[/url] on having a base64 decoder and encoder. Go vote!

sjasja at 2007-7-7 11:29:25 > top of Java-index,Administration Tools,Sun Connection...
# 2

> I guess if there is a reason it would be that there are an

> infinite number of possible algorithms, so necessarily

> they can't all be there

No, there is a [url=http://www.faqs.org/rfcs/rfc3548.html]standard[/url] method of encoding for base64 - I have also often wondered why Sun didn't make a public implementation of this standard as part of their API.

scorbett at 2007-7-7 11:29:25 > top of Java-index,Administration Tools,Sun Connection...
# 3

> > I guess if there is a reason it would be that there are an

> > infinite number of possible algorithms, so necessarily

> > they can't all be there

>

> No,

Yes, there are an infinite number of algorithms. Base64 encoding is one (well, strictly speaking, it isn't, it's more like a method; encoding can be done using many algorithms).

ASCII-to-EBDIC conversion isn't there, or Newton's square root, or shell sort, or a B-tree manipulation library, or... Because there are an infinite number of algorithms, and you got to draw the line somewhere. The answer to "explain why feature X isn't there" is "because."

If Base64 seems so important it should be in the JDK, and using one of the freely available third party ones isn't possible for some reason, you could try voting for the RFE.

sjasja at 2007-7-7 11:29:25 > top of Java-index,Administration Tools,Sun Connection...
# 4
Sorry, I misread your post... I thought you were saying that there are many ways to implement Base64, when really there's only one (standard) way.My bad.And yes, I did vote for the RFE, since Base64 is a pretty handy thing to have around.
scorbett at 2007-7-7 11:29:25 > top of Java-index,Administration Tools,Sun Connection...
# 5
There would be no questions if Base64 wasn't already there - unofficially. I suppose if Sun had to include it - it definitely worth including officially.
alexey.philimonov at 2007-7-7 11:29:25 > top of Java-index,Administration Tools,Sun Connection...
# 6
The following thread provides a documented way to do Base64 encoding using the Java API. http://forum.java.sun.com/thread.jsp?forum=31&thread=477461
jschell at 2007-7-7 11:29:25 > top of Java-index,Administration Tools,Sun Connection...
# 7

> Could anybody explain me why Sun don't include Base64

> encoding-decoding in an official API?

This is not rocket science. Many implementations exist. For example, BASE64EncoderStream.java and BASE64DecoderStream.java can be very useful, especially if you are already working with javamail or the J2EE reference implementation.

% javap -classpath $J2EE_HOME/lib/j2ee.jar com.sun.mail.util.BASE64EncoderStream

Compiled from BASE64EncoderStream.java

public class com.sun.mail.util.BASE64EncoderStream extends java.io.FilterOutputStream {

public com.sun.mail.util.BASE64EncoderStream(java.io.OutputStream,int);

public com.sun.mail.util.BASE64EncoderStream(java.io.OutputStream);

public void write(byte[], int, int) throws java.io.IOException;

public void write(byte[]) throws java.io.IOException;

public void write(int) throws java.io.IOException;

public void flush() throws java.io.IOException;

public void close() throws java.io.IOException;

public static byte encode(byte[])[];

static {};

}

% javap -classpath $J2EE_HOME/lib/j2ee.jar com.sun.mail.util.BASE64DecoderStream

Compiled from BASE64DecoderStream.java

public class com.sun.mail.util.BASE64DecoderStream extends java.io.FilterInputStream {

public com.sun.mail.util.BASE64DecoderStream(java.io.InputStream);

public int read() throws java.io.IOException;

public int read(byte[], int, int) throws java.io.IOException;

public boolean markSupported();

public int available() throws java.io.IOException;

public static byte decode(byte[])[];

static {};

}

Download the J2EE RI (Reference Implementation) source bundle from this URL:

http://wwws.sun.com/software/communitysource/index.html

look for the code under:

j2sdkee.....src/javamail/src/share/classes/com/sun/mail/util

timbell at 2007-7-7 11:29:25 > top of Java-index,Administration Tools,Sun Connection...
# 8

> > Could anybody explain me why Sun don't include

> Base64

> > encoding-decoding in an official API?

>

> This is not rocket science. Many implementations

> exist. For example, BASE64EncoderStream.java

> and BASE64DecoderStream.java can be very

> useful, especially if you are already working with

> javamail or the J2EE reference implementation.

My presumpation based on the OPs specific question about an official API suggests that the answer is still no.

Reference implementations by definition are not "official". They are intended to do nothing but demonstrate how one might implement an API, much like the java tutorial exists to demonstrate how java works.

And hauling around the entire implementation (which is probably required by the license) is probably overkill given that there are other implementations (none of which are "official" though.)

Not to mention of course that given that the package for BASE64EncoderStream is com.sun... it basically falls under the same restrictions that the base64 encoder that already is in the JVM has.

jschell at 2007-7-7 11:29:25 > top of Java-index,Administration Tools,Sun Connection...
# 9

I voted for that RFE more than two years ago and still Sun hasn't bothered making an existing com.sun class public. More than 2,000 classes in the J2SE and still no Base64. I guess we need 10,000 classes before we get one that's pretty useful for certain things. I guess creating a hundred new classes is easier for Sun than moving one from one package to another. Yes, there are other implementations out there but I cannot see why Base64 cannot be one of the standard classes.

cknelsen at 2007-7-7 11:29:25 > top of Java-index,Administration Tools,Sun Connection...