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