Esempio n. 1
0
  /**
   * Upload a local file to a URL
   *
   * @return true if successful
   */
  public boolean upload(String fileName, String url) {
    Data remote = Data.factory(url);
    Data local = Data.factory(fileName);

    // Sanity checks
    if (!remote.isRemote()) {
      System.err.println("Cannot upload to non-remote URL: " + url);
      return false;
    }

    if (!local.isFile()) {
      System.err.println("Cannot upload non-file: " + fileName);
      return false;
    }

    if (!local.exists()) {
      System.err.println("Local file does not exists: " + fileName);
      return false;
    }

    if (!local.canRead()) {
      System.err.println("Cannot read local file : " + fileName);
      return false;
    }

    // Already uploaded? Nothing to do
    if (remote.isUploaded(fileName)) {
      if (verbose) System.err.println("Remote file is up to date, no upload required: " + url);
      return true;
    }

    return remote.upload(fileName);
  }
Esempio n. 2
0
  /**
   * Download a URL to a local file
   *
   * @return true if successful
   */
  public boolean download(String url, String fileName) {
    Data remote = Data.factory(url);

    // Sanity checks
    if (!remote.isRemote()) {
      System.err.println("Cannot download non-remote URL: " + url);
      return false;
    }

    if (!remote.isFile()) {
      System.err.println("Cannot download non-file: " + url);
      return false;
    }

    // Already downloaded? Nothing to do
    if (remote.isDownloaded(fileName)) {
      if (verbose)
        System.err.println("Local file is up to date, no download required: " + fileName);
      return true;
    }

    return remote.download(fileName);
  }
Esempio n. 3
0
 /**
  * Get canonical path to file using thread's 'current dir' to de-reference relative paths
  *
  * <p>Warning: When un-serializing a task form a checkpoint, threads are not initialized, thus
  * they are null
  */
 public static Data data(String url) {
   BdsThread bdsThread = BdsThreads.getInstance().get();
   if (bdsThread == null) return Data.factory(url);
   return bdsThread.data(url);
 }