1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
public class Main {
public static void testEncodeDecode() throws IOException{
//Encodage
FileInputStream fis = new FileInputStream("Coucher de soleil.gif");
BufferedInputStream bis = new BufferedInputStream(fis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BASE64Encoder be = new BASE64Encoder();
//Encodage du flux
be.encodeBuffer(bis,baos);
//be.
fis.close();
bis.close();
FileOutputStream fos = new FileOutputStream("Soleil.gif");
BufferedOutputStream bos = new BufferedOutputStream(fos);
PrintWriter pw = new PrintWriter(bos);
BASE64Decoder bd = new BASE64Decoder();
pw.print(new String(bd.decodeBuffer(baos.toString())));
pw.flush();
pw.close();
fos.close();
baos.close();
}
public static void main(String[] args) {
testEncodeDecode();
}
} |
Partager