1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| package org.apache.geronimo.mail.util; |
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 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
0
| public static byte[] encode(
|
34 |
| byte[] data) |
35 |
| { |
36 |
0
| ByteArrayOutputStream bOut = new ByteArrayOutputStream();
|
37 |
| |
38 |
0
| try
|
39 |
| { |
40 |
0
| encoder.encode(data, 0, data.length, bOut);
|
41 |
| } |
42 |
| catch (IOException e) |
43 |
| { |
44 |
0
| throw new RuntimeException("exception encoding base64 string: " + e);
|
45 |
| } |
46 |
| |
47 |
0
| return bOut.toByteArray();
|
48 |
| } |
49 |
| |
50 |
| |
51 |
| |
52 |
| |
53 |
| |
54 |
| |
55 |
0
| public static int encode(
|
56 |
| byte[] data, |
57 |
| OutputStream out) |
58 |
| throws IOException |
59 |
| { |
60 |
0
| return encoder.encode(data, 0, data.length, out);
|
61 |
| } |
62 |
| |
63 |
| |
64 |
| |
65 |
| |
66 |
| |
67 |
| |
68 |
0
| public static int encode(
|
69 |
| byte[] data, |
70 |
| int off, |
71 |
| int length, |
72 |
| OutputStream out) |
73 |
| throws IOException |
74 |
| { |
75 |
0
| return encoder.encode(data, off, length, out);
|
76 |
| } |
77 |
| |
78 |
| |
79 |
| |
80 |
| |
81 |
| |
82 |
| |
83 |
0
| public static byte[] decode(
|
84 |
| byte[] data) |
85 |
| { |
86 |
0
| ByteArrayOutputStream bOut = new ByteArrayOutputStream();
|
87 |
| |
88 |
0
| try
|
89 |
| { |
90 |
0
| encoder.decode(data, 0, data.length, bOut);
|
91 |
| } |
92 |
| catch (IOException e) |
93 |
| { |
94 |
0
| throw new RuntimeException("exception decoding base64 string: " + e);
|
95 |
| } |
96 |
| |
97 |
0
| return bOut.toByteArray();
|
98 |
| } |
99 |
| |
100 |
| |
101 |
| |
102 |
| |
103 |
| |
104 |
| |
105 |
0
| public static byte[] decode(
|
106 |
| String data) |
107 |
| { |
108 |
0
| ByteArrayOutputStream bOut = new ByteArrayOutputStream();
|
109 |
| |
110 |
0
| try
|
111 |
| { |
112 |
0
| encoder.decode(data, bOut);
|
113 |
| } |
114 |
| catch (IOException e) |
115 |
| { |
116 |
0
| throw new RuntimeException("exception decoding base64 string: " + e);
|
117 |
| } |
118 |
| |
119 |
0
| return bOut.toByteArray();
|
120 |
| } |
121 |
| |
122 |
| |
123 |
| |
124 |
| |
125 |
| |
126 |
| |
127 |
| |
128 |
0
| public static int decode(
|
129 |
| String data, |
130 |
| OutputStream out) |
131 |
| throws IOException |
132 |
| { |
133 |
0
| return encoder.decode(data, out);
|
134 |
| } |
135 |
| |
136 |
| |
137 |
| |
138 |
| |
139 |
| |
140 |
| |
141 |
| |
142 |
| |
143 |
| |
144 |
| |
145 |
| |
146 |
2
| public static int decode(byte [] data, OutputStream out) throws IOException
|
147 |
| { |
148 |
2
| return encoder.decode(data, 0, data.length, out);
|
149 |
| } |
150 |
| } |