MDi JLib
1.7.4

com.microdeveloper.util.io
Class MIMEBase64

java.lang.Object
  extended by com.microdeveloper.util.io.MIMEBase64

public class MIMEBase64
extends Object

Performs MIMEBase64 encoding functions for encoding files.

Base64 uses a 65 character subset of US-ASCII,
allowing 6 bits for each character so the character
"m" with a Base64 value of 38, when represented
in binary form, is 100110.

With a text string, let's say "men" is encoded this
is what happens :

The text string is converted into its US-ASCII value.

The character "m" has the decimal value of 109
The character "e" has the decimal value of 101
The character "n" has the decimal value of 110

When converted to binary the string looks like this :

m 01101101
e 01100101
n 01101110

These three "8-bits" are concatenated to make a
24 bit stream
011011010110010101101110

This 24 bit stream is then split up into 4 6-bit
sections
011011 010110 010101 101110

We now have 4 values. These binary values are
converted to decimal form
27 22 21 46

And the corresponding Base64 character are :
b W V u

The encoding is always on a three characters basis
(to have a set of 4 Base64 characters). To encode one
or two then, we use the special character "=" to pad
until 4 base64 characters is reached.

ex. encode "me"

01101101 01100101
0110110101100101
011011 010110 0101
111111 (AND to fill the missing bits)
011011 010110 010100
b W U
b W U = ("=" is the padding character)

so "bWU=" is the base64 equivalent.

encode "m"

01101101
011011 01
111111 (AND to fill the missing bits)
011011 010000
b Q = = (two paddings are added)

Finally, MIME specifies that lines are 76 characters wide maximum.

Since:
1.1
Version:
1.0
Author:
MicroDeveloper, Inc.

Field Summary
(package private) static String[] BaseTable
           
 
Constructor Summary
MIMEBase64()
           
 
Method Summary
static void encode(String filename, BufferedWriter out)
          Encodes the given file and outputs to the given BufferedWriter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BaseTable

static String[] BaseTable
Constructor Detail

MIMEBase64

public MIMEBase64()
Method Detail

encode

public static void encode(String filename,
                          BufferedWriter out)
Encodes the given file and outputs to the given BufferedWriter.

Parameters:
filename - path to the file to write to
out - BufferedWriter to use for the output

MDi JLib
1.7.4

Copyright©2001-2007 MicroDeveloper, Inc. All Rights Reserved.