1 7 8 package org.enhydra.oyster.util; 9 10 14 public class Display { 15 16 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 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 integ = new Integer (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 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 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 |