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