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