示例#1
0
文件: U.java 项目: abinns/bdmds
 /**
  * A helper method which cleans up code, handles the try-catch so the calling method doesn't have
  * to.
  *
  * @param millis the number of milliseconds to sleep.
  */
 public static void sleep(long millis) {
   try {
     Thread.sleep(millis);
   } catch (InterruptedException e) {
     U.e("Error sleeping", e);
   }
 }
示例#2
0
文件: U.java 项目: abinns/bdmds
 /**
  * Tries to close the passed stream, if it is not null. If it encounters an exception, it logs it
  * and continues.
  *
  * @param message the message to log on IO exception
  * @param stream the stream to try and close
  */
 public static void tryCloseStream(String message, Closeable stream) {
   if (stream != null)
     try {
       stream.close();
     } catch (IOException e) {
       U.e(message, e);
     }
 }
示例#3
0
文件: U.java 项目: abinns/bdmds
  /**
   * Calls the specified method with the specified parameters, checking to make sure passed
   * arguments match required ones before attempting an invocation.
   *
   * @param <T>
   * @param method is the method which is being attempted to be invoked.
   * @param input is a var-args (any number of options, or an array) for the parameters.
   * @throws InvalidParameterException if the passed options don't match with the arguments required
   *     by the method.
   */
  @SuppressWarnings("unchecked")
  public static <T> T carefulCall(Method method, Object target, Object... params)
      throws InvalidParameterException {
    Object res = null;
    // int i = 0;
    // for (Class<?> c : method.getParameterTypes())
    // if (!c.equals(U.getUnBoxedType(params[i++].getClass())))
    // U.w("Input item " + params[i - 1].getClass().getName() +
    // " may be incompatible with " + c.getName() + " for method " +
    // method.getName());

    try {
      res = method.invoke(target, params);
    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
      U.e("Error, could not properly call method " + method.getName(), e);
    }
    return (T) res;
  }