395N/A/*
2362N/A * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
395N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
395N/A *
395N/A * This code is free software; you can redistribute it and/or modify it
395N/A * under the terms of the GNU General Public License version 2 only, as
395N/A * published by the Free Software Foundation.
395N/A *
395N/A * This code is distributed in the hope that it will be useful, but WITHOUT
395N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
395N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
395N/A * version 2 for more details (a copy is included in the LICENSE file that
395N/A * accompanied this code).
395N/A *
395N/A * You should have received a copy of the GNU General Public License version
395N/A * 2 along with this work; if not, write to the Free Software Foundation,
395N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
395N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
395N/A */
395N/A
395N/A/**/
395N/A
395N/Apublic class Decode {
395N/A private static boolean isAscii(char c) {
395N/A return c < '\u0080';
395N/A }
395N/A
395N/A private static boolean isPrintable(char c) {
395N/A return ('\u0020' < c) && (c < '\u007f');
395N/A }
395N/A
395N/A public static void main(String[] args) throws Throwable {
395N/A if (args.length < 2)
395N/A throw new Exception("Usage: java Decode CHARSET BYTE [BYTE ...]");
395N/A String cs = args[0];
395N/A byte[] bytes = new byte[args.length-1];
395N/A for (int i = 1; i < args.length; i++) {
395N/A String arg = args[i];
395N/A bytes[i-1] =
395N/A (arg.length() == 1 && isAscii(arg.charAt(0))) ?
395N/A (byte) arg.charAt(0) :
395N/A arg.equals("ESC") ? 0x1b :
395N/A arg.equals("SO") ? 0x0e :
395N/A arg.equals("SI") ? 0x0f :
395N/A arg.equals("SS2") ? (byte) 0x8e :
395N/A arg.equals("SS3") ? (byte) 0x8f :
395N/A arg.matches("0x.*") ? Integer.decode(arg).byteValue() :
395N/A Integer.decode("0x"+arg).byteValue();
395N/A }
395N/A String s = new String(bytes, cs);
395N/A
395N/A for (int j = 0; j < s.length(); j++) {
395N/A if (j > 0)
395N/A System.out.print(' ');
395N/A char c = s.charAt(j);
395N/A if (isPrintable(c))
395N/A System.out.print(c);
395N/A else if (c == '\u001b') System.out.print("ESC");
395N/A else
395N/A System.out.printf("\\u%04x", (int) c);
395N/A }
395N/A System.out.print("\n");
395N/A }
395N/A}