private static void appendThrowable(Throwable thrown, StringBuilder sb) {
    StringWriter stringWriter = new StringWriter();
    thrown.printStackTrace(new PrintWriter(stringWriter));
    String[] lines = StringUtil.splitByLines(stringWriter.toString());
    int maxStackSize = 1024, maxExtraSize = 256;
    if (lines.length > maxStackSize + maxExtraSize) {
      String[] res = new String[maxStackSize + maxExtraSize + 1];
      System.arraycopy(lines, 0, res, 0, maxStackSize);
      res[maxStackSize] = "\t...";
      System.arraycopy(lines, lines.length - maxExtraSize, res, maxStackSize + 1, maxExtraSize);
      for (int i = 0; i < res.length; i++) {
        if (i > 0) {
          sb.append(LINE_SEPARATOR);
        }
        sb.append(res[i]);
      }
    }
    else {
      sb.append(stringWriter.getBuffer());
    }
  }
private static void appendThrowable(Throwable thrown, StringBuilder sb)