Exemplo n.º 1
0
 public static void printFields(Class<?> javaClass) {
   final String className = javaClass.getSimpleName();
   TTY.println(className + " {");
   for (final Field field : javaClass.getFields()) {
     printField(field, false);
   }
   TTY.println("}");
 }
Exemplo n.º 2
0
  public static void printSection(String name, char sectionCharacter) {

    String header = " " + name + " ";
    int remainingCharacters = PRINTING_LINE_WIDTH - header.length();
    int leftPart = remainingCharacters / 2;
    int rightPart = remainingCharacters - leftPart;
    for (int i = 0; i < leftPart; i++) {
      TTY.print(sectionCharacter);
    }

    TTY.print(header);

    for (int i = 0; i < rightPart; i++) {
      TTY.print(sectionCharacter);
    }

    TTY.println();
  }
Exemplo n.º 3
0
  /**
   * Prints entries in a byte array as space separated hex values to {@link TTY}.
   *
   * @param address an address at which the bytes are located. This is used to print an address
   *     prefix per line of output.
   * @param array the array containing the bytes to print
   * @param offset the offset in {@code array} of the values to print
   * @param length the number of values from {@code array} print
   * @param bytesPerLine the number of values to print per line of output
   */
  public static void printBytes(
      long address, byte[] array, int offset, int length, int bytesPerLine) {
    assert bytesPerLine > 0;
    boolean newLine = true;
    for (int i = 0; i < length; i++) {
      if (newLine) {
        TTY.printf("%08x: ", address + i);
        newLine = false;
      }
      TTY.printf("%02x ", array[i]);
      if (i % bytesPerLine == bytesPerLine - 1) {
        TTY.println();
        newLine = true;
      }
    }

    if (length % bytesPerLine != bytesPerLine) {
      TTY.println();
    }
  }
Exemplo n.º 4
0
 public static void printField(final Field field, boolean tabbed) {
   final String fieldName = String.format("%35s", field.getName());
   try {
     String prefix = tabbed ? "" : "    " + fieldName + " = ";
     String postfix = tabbed ? "\t" : "\n";
     if (field.getType() == int.class) {
       TTY.print(prefix + field.getInt(null) + postfix);
     } else if (field.getType() == boolean.class) {
       TTY.print(prefix + field.getBoolean(null) + postfix);
     } else if (field.getType() == float.class) {
       TTY.print(prefix + field.getFloat(null) + postfix);
     } else if (field.getType() == String.class) {
       TTY.print(prefix + field.get(null) + postfix);
     } else if (field.getType() == Map.class) {
       Map<?, ?> m = (Map<?, ?>) field.get(null);
       TTY.print(prefix + printMap(m) + postfix);
     } else {
       TTY.print(prefix + field.get(null) + postfix);
     }
   } catch (IllegalAccessException e) {
     // do nothing.
   }
 }
Exemplo n.º 5
0
 public static void warning(String string) {
   TTY.println("WARNING: " + string);
 }