Exemple #1
0
 private static void print(OutputStream stream, Object object) {
   if (object == null) {
     printBytes(stream, "(null)".getBytes());
   } else if (object instanceof Iterable) {
     printIterable(stream, (Iterable) object);
   } else if (object instanceof Throwable) {
     printThrowable(stream, (Throwable) object);
   } else if (object.getClass().isArray()) {
     Object[] array = toObjectArray(object);
     printArray(stream, array);
   } else {
     printBytes(stream, object.toString().getBytes());
   }
 }
Exemple #2
0
 private static void printThrowable(OutputStream stream, Throwable throwable) {
   printBytes(stream, ("Exception " + throwable.toString()).getBytes());
   printNewLine(stream);
   StackTraceElement[] stackTraceElements = throwable.getStackTrace();
   for (int i = stackTraceElements.length - 1; i >= 0; i--) {
     StackTraceElement element = stackTraceElements[i];
     printBytes(stream, element.getFileName().getBytes());
     printBytes(stream, ":".getBytes());
     printBytes(stream, String.valueOf(element.getLineNumber()).getBytes());
     printNewLine(stream);
   }
   if (throwable.getCause() != null) {
     printBytes(stream, "Caused by:\n".getBytes());
     printThrowable(stream, throwable.getCause());
   }
 }