Ejemplo n.º 1
0
  public static Task createDownloadTask(
      ApiSession sess,
      String servicename,
      Path local,
      CommonPath remote,
      Struct storeParams,
      boolean allowResume) {
    DownloadFile work = new DownloadFile();
    work.session = sess;

    RecordStruct params =
        new RecordStruct(
            new FieldStruct("LocalPath", local),
            new FieldStruct("RemotePath", remote),
            new FieldStruct("ServiceName", servicename),
            new FieldStruct("TransferParams", storeParams));

    if (allowResume && Files.exists(local)) {
      try {
        params.setField("Offset", Files.size(local));
      } catch (IOException x) {
        Logger.error("Unable to get file size for: " + local);
        return null;
      }
    }

    return new Task()
        .withTitle("Download file " + local)
        .withWork(work)
        .withSubContext()
        .withParams(params)
        .withTimeout(1)
        .withDeadline(0);
  }