1 17 18 package org.apache.geronimo.util.encoders; 19 20 import java.io.ByteArrayOutputStream ; 21 import java.io.IOException ; 22 import java.io.OutputStream ; 23 24 public class Base64 25 { 26 private static final Encoder encoder = new Base64Encoder(); 27 28 33 public static byte[] encode( 34 byte[] data) 35 { 36 ByteArrayOutputStream bOut = new ByteArrayOutputStream (); 37 38 try 39 { 40 encoder.encode(data, 0, data.length, bOut); 41 } 42 catch (IOException e) 43 { 44 throw new RuntimeException ("exception encoding base64 string: " + e); 45 } 46 47 return bOut.toByteArray(); 48 } 49 50 55 public static int encode( 56 byte[] data, 57 OutputStream out) 58 throws IOException 59 { 60 return encoder.encode(data, 0, data.length, out); 61 } 62 63 68 public static int encode( 69 byte[] data, 70 int off, 71 int length, 72 OutputStream out) 73 throws IOException 74 { 75 return encoder.encode(data, off, length, out); 76 } 77 78 83 public static byte[] decode( 84 byte[] data) 85 { 86 ByteArrayOutputStream bOut = new ByteArrayOutputStream (); 87 88 try 89 { 90 encoder.decode(data, 0, data.length, bOut); 91 } 92 catch (IOException e) 93 { 94 throw new RuntimeException ("exception decoding base64 string: " + e); 95 } 96 97 return bOut.toByteArray(); 98 } 99 100 105 public static byte[] decode( 106 String data) 107 { 108 ByteArrayOutputStream bOut = new ByteArrayOutputStream (); 109 110 try 111 { 112 encoder.decode(data, bOut); 113 } 114 catch (IOException e) 115 { 116 throw new RuntimeException ("exception decoding base64 string: " + e); 117 } 118 119 return bOut.toByteArray(); 120 } 121 122 128 public static int decode( 129 String data, 130 OutputStream out) 131 throws IOException 132 { 133 return encoder.decode(data, out); 134 } 135 } 136 | Popular Tags |