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.InputStream; |
23 |
| import java.io.OutputStream; |
24 |
| |
25 |
| public class QuotedPrintable { |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
0
| public static byte[] encode(
|
37 |
| byte[] data) |
38 |
| { |
39 |
0
| return encode(data, 0, data.length);
|
40 |
| } |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
| |
46 |
| |
47 |
0
| public static byte[] encode(
|
48 |
| byte[] data, |
49 |
| int off, |
50 |
| int length) |
51 |
| { |
52 |
0
| QuotedPrintableEncoder encoder = new QuotedPrintableEncoder();
|
53 |
| |
54 |
0
| ByteArrayOutputStream bOut = new ByteArrayOutputStream();
|
55 |
| |
56 |
0
| try
|
57 |
| { |
58 |
0
| encoder.encode(data, off, length, bOut);
|
59 |
| } |
60 |
| catch (IOException e) |
61 |
| { |
62 |
0
| throw new RuntimeException("exception encoding Q-P encoded string: " + e);
|
63 |
| } |
64 |
| |
65 |
0
| return bOut.toByteArray();
|
66 |
| } |
67 |
| |
68 |
| |
69 |
| |
70 |
| |
71 |
| |
72 |
| |
73 |
0
| public static int encode(
|
74 |
| byte[] data, |
75 |
| OutputStream out) |
76 |
| throws IOException |
77 |
| { |
78 |
0
| QuotedPrintableEncoder encoder = new QuotedPrintableEncoder();
|
79 |
| |
80 |
0
| return encoder.encode(data, 0, data.length, out);
|
81 |
| } |
82 |
| |
83 |
| |
84 |
| |
85 |
| |
86 |
| |
87 |
| |
88 |
0
| public static int encode(
|
89 |
| byte[] data, |
90 |
| int off, |
91 |
| int length, |
92 |
| OutputStream out) |
93 |
| throws IOException |
94 |
| { |
95 |
0
| QuotedPrintableEncoder encoder = new QuotedPrintableEncoder();
|
96 |
0
| return encoder.encode(data, 0, data.length, out);
|
97 |
| } |
98 |
| |
99 |
| |
100 |
| |
101 |
| |
102 |
| |
103 |
| |
104 |
0
| public static byte[] decode(
|
105 |
| byte[] data) |
106 |
| { |
107 |
0
| ByteArrayOutputStream bOut = new ByteArrayOutputStream();
|
108 |
| |
109 |
0
| QuotedPrintableEncoder encoder = new QuotedPrintableEncoder();
|
110 |
0
| try
|
111 |
| { |
112 |
0
| encoder.decode(data, 0, data.length, bOut);
|
113 |
| } |
114 |
| catch (IOException e) |
115 |
| { |
116 |
0
| throw new RuntimeException("exception decoding Q-P encoded string: " + e);
|
117 |
| } |
118 |
| |
119 |
0
| return bOut.toByteArray();
|
120 |
| } |
121 |
| |
122 |
| |
123 |
| |
124 |
| |
125 |
| |
126 |
| |
127 |
0
| public static byte[] decode(
|
128 |
| String data) |
129 |
| { |
130 |
0
| QuotedPrintableEncoder encoder = new QuotedPrintableEncoder();
|
131 |
0
| ByteArrayOutputStream bOut = new ByteArrayOutputStream();
|
132 |
| |
133 |
0
| try
|
134 |
| { |
135 |
0
| encoder.decode(data, bOut);
|
136 |
| } |
137 |
| catch (IOException e) |
138 |
| { |
139 |
0
| throw new RuntimeException("exception decoding Q-P encoded string: " + e);
|
140 |
| } |
141 |
| |
142 |
0
| return bOut.toByteArray();
|
143 |
| } |
144 |
| |
145 |
| |
146 |
| |
147 |
| |
148 |
| |
149 |
| |
150 |
0
| public static int decode(
|
151 |
| String data, |
152 |
| OutputStream out) |
153 |
| throws IOException |
154 |
| { |
155 |
0
| QuotedPrintableEncoder encoder = new QuotedPrintableEncoder();
|
156 |
0
| return encoder.decode(data, out);
|
157 |
| } |
158 |
| |
159 |
| |
160 |
| |
161 |
| |
162 |
| |
163 |
| |
164 |
| |
165 |
| |
166 |
| |
167 |
| |
168 |
| |
169 |
0
| public static int decode(byte [] data, OutputStream out) throws IOException
|
170 |
| { |
171 |
0
| QuotedPrintableEncoder encoder = new QuotedPrintableEncoder();
|
172 |
0
| return encoder.decode(data, 0, data.length, out);
|
173 |
| } |
174 |
| } |
175 |
| |