Example #1
0
  protected UnicodeTranslator(String[] unicode2table) {
    if (unicode2table == null) throw new IllegalArgumentException("unicode2table is null");

    Field[] fields = Unicode.class.getFields();

    for (int i = 0; i < fields.length; i++) {
      if (fields[i].getModifiers() != (Modifier.FINAL | Modifier.PUBLIC | Modifier.STATIC))
        continue;
      try {
        Object o = fields[i].get(Unicode.class);
        if (o instanceof String) {
          boolean found = false;
          for (int j = 0; j < unicode2table.length; j += 2) found |= o.equals(unicode2table[j]);
          if (!found)
            throw new IllegalArgumentException(
                "Unicode char '"
                    + o
                    + "' ("
                    + fields[i].getName()
                    + ") not mapped by class "
                    + getClass().getName());
        }
      } catch (IllegalAccessException e) {
        Util.printStackTrace(e);
      }
    }
  }
Example #2
0
 private static String getException(Throwable exception) {
   if (exception == null) return "";
   ByteArrayOutputStream bout = new ByteArrayOutputStream();
   PrintStream out = new PrintStream(bout);
   Util.printStackTrace(exception, out);
   out.flush();
   String result = bout.toString();
   out.close();
   return result;
 }
Example #3
0
  public static void main(String[] argv) {
    Field[] fields = Unicode.class.getFields();

    for (int i = 0; i < fields.length; i++) {
      if (fields[i].getModifiers() != (Modifier.FINAL | Modifier.PUBLIC | Modifier.STATIC))
        continue;
      try {
        Object o = fields[i].get(Unicode.class);
        if (o instanceof String)
          System.out.println(
              o + ":" + Integer.toHexString(((String) o).charAt(0)) + ":" + fields[i].getName());
      } catch (IllegalAccessException e) {
        Util.printStackTrace(e);
      }
    }
  }