File: list.java

package info (click to toggle)
android-platform-build 21-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,204 kB
  • ctags: 3,464
  • sloc: python: 3,797; cpp: 2,788; cs: 1,971; sh: 1,302; makefile: 1,114; ansic: 917; java: 734
file content (35 lines) | stat: -rw-r--r-- 1,023 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.io.*;

public class list {
    private static char nibble(int c) {
        return (char)(c < 10 ? ('0' + c) : ('a' + (c-10)));
    }
    public static void main(String[] argv)
    {
        ByteArrayOutputStream stream = new ByteArrayOutputStream(100);
        OutputStreamWriter writer = null;
        try {
            writer = new OutputStreamWriter(stream, "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace(System.err);
        }

        int n = Integer.parseInt(argv[1], 16);
        try {
            writer.write(n);
            writer.close();
        } catch (IOException e) {
            e.printStackTrace(System.err);
        }

        byte[] array = stream.toByteArray();

        System.out.print("        case '" + argv[0] + "':   return \"");
        for (int i=0; i<array.length; i++) {
            int b = array[i];
            System.out.print("\\x" + nibble((b >> 4) & 0x0f) + nibble(b & 0xf));
        }
        System.out.println("\";");
    }
}