KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > oyster > util > Display


1 /*
2  * Title: Oyster Project
3  * Description: S/MIME email sending capabilities
4  * @Author Vladimir Radisic
5  * @Version 2.1.5
6  */

7
8 package org.enhydra.oyster.util;
9
10 /**
11  * Methods of this class are used for displaying byte array on screen in
12  * different forms.
13  */

14 public class Display {
15
16   /**
17    * Prints to screen byte array as hex values
18    * @param in input byte array
19    */

20   public static void printByteArrayAsHex (byte[] in) {
21     if (in.length == 0)
22       System.out.println("Byte array is null!\n");
23     else {
24       String JavaDoc hex = "";
25       for (int i = 0; i != in.length; i++) {
26         if (((i%16) == 0) && (i != 0)) {
27           System.out.print(hex+"\n");
28           hex = "";
29         }
30         int h = (((int)in[i]) & 0xFF);
31         Integer JavaDoc integ = new Integer JavaDoc(h);
32         if(integ.toHexString(h).length() == 1)
33           hex = hex + "0" + integ.toHexString(h) + "\t";
34         else
35           hex = hex + integ.toHexString(h) + "\t";
36       }
37       System.out.println(hex+"\n\n");
38     }
39   }
40
41   /**
42    * Prints to screen byte array as character string
43    * @param in input byte array
44    */

45   public static void printByteArrayAsChar (byte[] in) {
46     if (in.length == 0)
47       System.out.println("Byte array is null!\n");
48     else {
49       for (int i = 0; i != in.length; i++) {
50         System.out.print((char)in[i]);
51         System.out.print('.');
52         }
53       System.out.println("\n");
54     }
55   }
56
57   /**
58    * Prints to screen byte array
59    * @param in input byte array
60    */

61   public static void printByteArray (byte[] in) {
62     if (in.length == 0)
63       System.out.println("Byte array is null!\n");
64     else {
65       for (int i = 0; i != in.length; i++) {
66         if (((i%16) == 0) && (i != 0))
67           System.out.print("\n");
68         System.out.print(in[i] + "\t");
69       }
70       System.out.println("\n");
71     }
72   }
73 }
74
75
76
77
Popular Tags