1 17 18 package org.apache.geronimo.util.encoders; 19 20 import java.io.ByteArrayOutputStream ; 21 import java.io.IOException ; 22 import java.io.OutputStream ; 23 24 public class Hex 25 { 26 private static final Encoder encoder = new HexEncoder(); 27 28 33 public static byte[] encode( 34 byte[] data) 35 { 36 return encode(data, 0, data.length); 37 } 38 39 44 public static byte[] encode( 45 byte[] data, 46 int off, 47 int length) 48 { 49 ByteArrayOutputStream bOut = new ByteArrayOutputStream (); 50 51 try 52 { 53 encoder.encode(data, off, length, bOut); 54 } 55 catch (IOException e) 56 { 57 throw new RuntimeException ("exception encoding Hex string: " + e); 58 } 59 60 return bOut.toByteArray(); 61 } 62 63 68 public static int encode( 69 byte[] data, 70 OutputStream out) 71 throws IOException 72 { 73 return encoder.encode(data, 0, data.length, out); 74 } 75 76 81 public static int encode( 82 byte[] data, 83 int off, 84 int length, 85 OutputStream out) 86 throws IOException 87 { 88 return encoder.encode(data, 0, data.length, out); 89 } 90 91 96 public static byte[] decode( 97 byte[] data) 98 { 99 ByteArrayOutputStream bOut = new ByteArrayOutputStream (); 100 101 try 102 { 103 encoder.decode(data, 0, data.length, bOut); 104 } 105 catch (IOException e) 106 { 107 throw new RuntimeException ("exception decoding Hex string: " + e); 108 } 109 110 return bOut.toByteArray(); 111 } 112 113 118 public static byte[] decode( 119 String data) 120 { 121 ByteArrayOutputStream bOut = new ByteArrayOutputStream (); 122 123 try 124 { 125 encoder.decode(data, bOut); 126 } 127 catch (IOException e) 128 { 129 throw new RuntimeException ("exception decoding Hex string: " + e); 130 } 131 132 return bOut.toByteArray(); 133 } 134 135 141 public static int decode( 142 String data, 143 OutputStream out) 144 throws IOException 145 { 146 return encoder.decode(data, out); 147 } 148 } 149 | Popular Tags |