// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.util.StringTokenizer;

public class ByteArray {
   private final static String hexValue[] = { "0", "1", "2", "3",
                                              "4", "5", "6", "7",
                                              "8", "9", "A", "B",
                                              "C", "D", "E", "F" };
   private byte[] data;
   public ByteArray() {
      data = new byte[0];
   }
   public ByteArray(String s) {
      StringTokenizer tok = new StringTokenizer(s, " ");
      int n = tok.countTokens();
      data = new byte[n];
      for (int i = 0; i < n; i++) data[i] = Integer.decode("0x" + tok.nextToken()).byteValue();
   }
   public String toString() {
      StringBuffer result = new StringBuffer();
      for(int i = 0; i < data.length; i++) {
         if(i > 0) result.append(" ");
         result.append(hexValue[(data[i] >> 4) & 0x0F]);
         result.append(hexValue[data[i] & 0x0F]);
      }
      return result.toString();
   }
   public void setData(byte[] d) {
      data = d;
   }
   public byte[] getData() {
      return data;
   }
}
