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