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 36 public class UrlBase64 37 { 38 private static final Encoder encoder = new UrlBase64Encoder(); 39 40 45 public static byte[] encode( 46 byte[] data) 47 { 48 ByteArrayOutputStream bOut = new ByteArrayOutputStream (); 49 50 try 51 { 52 encoder.encode(data, 0, data.length, bOut); 53 } 54 catch (IOException e) 55 { 56 throw new RuntimeException ("exception encoding URL safe base64 string: " + e); 57 } 58 59 return bOut.toByteArray(); 60 } 61 62 67 public static int encode( 68 byte[] data, 69 OutputStream out) 70 throws IOException 71 { 72 return encoder.encode(data, 0, data.length, out); 73 } 74 75 80 public static byte[] decode( 81 byte[] data) 82 { 83 ByteArrayOutputStream bOut = new ByteArrayOutputStream (); 84 85 try 86 { 87 encoder.decode(data, 0, data.length, bOut); 88 } 89 catch (IOException e) 90 { 91 throw new RuntimeException ("exception decoding URL safe base64 string: " + e); 92 } 93 94 return bOut.toByteArray(); 95 } 96 97 103 public static int decode( 104 byte[] data, 105 OutputStream out) 106 throws IOException 107 { 108 return encoder.decode(data, 0, data.length, out); 109 } 110 111 116 public static byte[] decode( 117 String data) 118 { 119 ByteArrayOutputStream bOut = new ByteArrayOutputStream (); 120 121 try 122 { 123 encoder.decode(data, bOut); 124 } 125 catch (IOException e) 126 { 127 throw new RuntimeException ("exception decoding URL safe base64 string: " + e); 128 } 129 130 return bOut.toByteArray(); 131 } 132 133 139 public static int decode( 140 String data, 141 OutputStream out) 142 throws IOException 143 { 144 return encoder.decode(data, out); 145 } 146 } 147 | Popular Tags |