Ejemplo n.º 1
0
  private int startUnchecked() {
    if (FileDownloadMonitor.isValid()) {
      FileDownloadMonitor.getMonitor().onRequestStart(this);
    }

    if (FileDownloadLog.NEED_LOG) {
      FileDownloadLog.v(
          this,
          "call start " + "url[%s], setPath[%s] listener[%s], tag[%s]",
          url,
          path,
          listener,
          tag);
    }

    boolean ready = true;

    try {
      _adjust();
      _checkFile(path);
    } catch (Throwable e) {
      ready = false;

      FileDownloadList.getImpl().add(this);
      FileDownloadList.getImpl().remove(this, catchException(e));
    }

    if (ready) {
      FileDownloadTaskLauncher.getImpl().launch(this);
    }

    return getId();
  }
Ejemplo n.º 2
0
  /**
   * start download
   *
   * <p>用于启动一个单独任务
   *
   * @return Download id
   */
  public int start() {
    if (FileDownloadMonitor.isValid()) {
      FileDownloadMonitor.getMonitor().onRequestStart(this);
    }

    if (FileDownloadLog.NEED_LOG) {
      FileDownloadLog.v(
          this,
          "call start " + "url[%s], setPath[%s] listener[%s], tag[%s]",
          url,
          path,
          listener,
          tag);
    }

    boolean ready = true;

    try {
      _adjust();
      _checkFile(path);
    } catch (Throwable e) {
      ready = false;

      setStatus(FileDownloadStatus.error);
      setEx(e);
      FileDownloadList.getImpl().add(this);
      FileDownloadList.getImpl().removeByError(this);
    }

    if (ready) {
      FileDownloadEventPool.getImpl().send2Service(new DownloadTaskEvent(this).requestStart());
    }

    return getDownloadId();
  }