1 import java.io.*; 2 3 public class list { nibble(int c)4 private static char nibble(int c) { 5 return (char)(c < 10 ? ('0' + c) : ('a' + (c-10))); 6 } main(String[] argv)7 public static void main(String[] argv) 8 { 9 ByteArrayOutputStream stream = new ByteArrayOutputStream(100); 10 OutputStreamWriter writer = null; 11 try { 12 writer = new OutputStreamWriter(stream, "utf-8"); 13 } catch (UnsupportedEncodingException e) { 14 e.printStackTrace(System.err); 15 } 16 17 int n = Integer.parseInt(argv[1], 16); 18 try { 19 writer.write(n); 20 writer.close(); 21 } catch (IOException e) { 22 e.printStackTrace(System.err); 23 } 24 25 byte[] array = stream.toByteArray(); 26 27 System.out.print(" case '" + argv[0] + "': return \""); 28 for (int i=0; i<array.length; i++) { 29 int b = array[i]; 30 System.out.print("\\x" + nibble((b >> 4) & 0x0f) + nibble(b & 0xf)); 31 } 32 System.out.println("\";"); 33 } 34 } 35 36