Tutorial Addendum on Data Encoding - Base64 Encoding

sportsappsios utilitiesappsios adventuregamesios
 31 December 18:00   

    



    



    

The afterward program , W3CBase64. java , shows how to use the W3C implementation.

    

 

    

/**

    

* W3CBase64. java

    

* Absorb (c) 2002 by Dr. Yang

    

*/

    

import java .io.*;

    

import org.w3c.tools.codec.*;

    

class W3CBase64 {

    

accessible changeless abandoned main(String[] a) {

    

Cord activity = a[0];

    

Cord inFile = a[1];

    

Cord outFile = a[2];

    

if (action.equals("encode")) {

    

encode(inFile,outFile);

    

} abroad if (action.equals("decode")) {

    

decode(inFile,outFile);

    

} abroad {

    

System.out.println("Please adjure the program with:");

    

System.out.println(" java W3CBase64 encode/decode in out");

    

}

    

}

    

clandestine changeless abandoned encode(String inFile, Cord outFile) {

    

try {

    

InputStream in = new FileInputStream(inFile);

    

OutputStream out = new FileOutputStream(outFile);

    

Base64Encoder encoder = new Base64Encoder(in,out);

    

encoder.process();

    

in.close();

    

out.close();

    

} bolt (IOException e) {

    

System.out.println(e.toString());

    

}

    

}

    

clandestine changeless abandoned decode(String inFile, Cord outFile) {

    

try {

    

InputStream in = new FileInputStream(inFile);

    

OutputStream out = new FileOutputStream(outFile);

    

Base64Decoder decoder = new Base64Decoder(in,out);

    

decoder.process();

    

in.close();

    

out.close();

    

} bolt (IOException e) {

    

System.out.println(e.toString());

    

} bolt (Base64FormatException e) {

    

System.out.println(e.toString());

    

}

    

}

    

}

    



    



    

Let s try this program by encoding and adaptation the java chic book produced by the Java

    

compiler:

    

 

    

javac W3CBase64.java

    

java W3CBase64 encode W3CBase64.class W3CBase64.b64

    

type W3CBase64.b64

    

java W3CBase64 break W3CBase64.b64 W3CBase64.cls

    

del W3CBase64.class

    

ren W3CBase64.cls W3CBase64.class

    

java W3CBase64 abc in out

    



    



    

As you can see from the "type W3CBase64.b64" command, the encoded achievement is accurately formatted

    

with 76 characters per line.

    



    

By active the decoded adaptation of the chic book at the end, you understand that the encoding and

    

decoding accomplishing works fine.

    



    

Sun Implementation

    



    

Another accomplishing of the Base64 algorithm is from the Brazil activity at sun.com.

    

You can download the antecedent cipher of this accomplishing at: http://research.sun.com/brazil/.

    



    

Here is the antecedent code:

    

 

    

/*

    

* Base64.java

    

*

    

* Brazil activity web appliance toolkit,

    

* consign version: 2.0

    

* Absorb (c) 2000-2002 Sun Microsystems, Inc.

    

*

    

* Sun Accessible Authorization Notice

    

*

    

* The capacity of this book are accountable to the Sun Accessible Authorization

    

* Adaptation 1.0 (the "License"). You may not use this book except

    

* in acquiescence with the License. A archetype of the Authorization is included

    

* as the book "license.terms", and aswell accessible

    

* at http://www.sun.com/

    

*

    

* The Aboriginal Cipher is from:

    

* Brazil activity web appliance toolkit absolution 2.0.

    

* The Antecedent Developer of the Aboriginal Cipher is: cstevens.

    

* Portions created by cstevens are Absorb (C) Sun Microsystems, Inc.

    

* All Rights Reserved.

    

*

    

* Contributor(s): cstevens, suhler.

    

*

    

* Version: 1.9

    

* Created by cstevens on 00/04/17

    

* Endure adapted by suhler on 02/07/24 10:49:48

    

*/

    

package sunlabs.brazil.util;

    

/**

    

* Account to base64 encode and break a string.

    

* @author Stephen Uhler

    

* @version 1.9, 02/07/24

    

*/

    

public chic Base64 {

    

changeless byte[] encodeData;

    

changeless Cord charSet =

    

"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

    



    

changeless {

    

encodeData = new byte[64];

    

for (int i = 0; i<64; i++) {

    

byte c = (byte) charSet.charAt(i);

    

encodeData[i] = c;

    

}

    

}

    

clandestine Base64() {}

    

/**

    

* base-64 encode a string

    

* @param s The ascii cord to encode

    

* @returns The base64 encoded result

    

*/

    

accessible changeless String

    

encode(String s) {

    

acknowledgment encode(s.getBytes());

    

}

    



    



    

 


Tags: action, program, system, application, class, project, brazil, catch, license, public, string

 w3cbase64, string, encode, base64, infile, static, outfile, encoding, decode, license, system, brazil, public, println, class, version, cstevens, implementation, project, encodedata, copyright, tostring, action, private, catch, program, , system out, brazil project, sun com, string outfile, string infile, static void, fileinputstream infile outputstream, new fileoutputstream outfile, web application toolkit, sun public license, new fileinputstream infile, infile string outfile, encoding base64 encoding, private static void, string infile string, data encoding base64,

Share Tutorial Addendum on Data Encoding - Base64 Encoding:
Digg it!   Google Bookmarks   Del.icio.us   Yahoo! MyWeb   Furl  Binklist   Reddit!   Stumble Upon   Technorati   Windows Live   Bookmark

Text link code :
Hyper link code:

Also see ...

Permalink
Article In : Computers & Technology  -  Encoding