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