Esempio n. 1
0
  /**
   * Main
   *
   * @param args
   */
  public static void main(String[] args) {

    boolean sameoutput = false;

    int copies = DFLT_COPIES;
    int maxDepots = DFLT_MAX_DEPOTS;
    int duration = DFLT_DURATION;
    int transferSize = DFLT_TRANSFERSIZE;
    int connections = DFLT_CONNECTIONS;
    String location = DFLT_LOCATION;

    String outputfilename = "";
    String inputfilename = "";

    String str = "";

    if (args.length == 0) {
      usage();
      System.exit(0);
    }

    for (int i = 0; i < args.length; i++) {
      String arg = args[i];
      if ((char) arg.charAt(0) == '-') {
        switch ((char) arg.charAt(1)) {
          case 'f':
            sameoutput = true;
            break;
          case 'H':
            i++;
            break;
          case 'c':
            copies = Integer.parseInt(args[i + 1]);
            i++;
            break;
          case 'o':
            outputfilename = args[i + 1];
            i++;
            break;
          case 'm':
            maxDepots = Integer.parseInt(args[i + 1]);
            i++;
            break;
          case 'n':
            break;
          case 'l':
            location = args[i + 1] + " " + args[i + 2];
            i += 2;
            break;
          case 'h':
            break;
          case 's':
            break;
          case 't':
            connections = Integer.parseInt(args[i + 1]);
            i++;
            break;
          case 'T':
            i++;
            break;
          case 'd':
            try {
              str = args[i + 1].toLowerCase();
              int p = str.length();
              if (str.endsWith("m")) {
                duration = Integer.parseInt(str.substring(0, p - 1)) * 60;
              } else if (str.endsWith("h")) {
                duration = Integer.parseInt(str.substring(0, p - 1)) * 3660;
              } else if (str.endsWith("d")) {
                duration = Integer.parseInt(str.substring(0, p - 1)) * 86400;
              } else {
                duration = Integer.parseInt(str);
              }
            } catch (Exception e) {
              System.out.println("Bad number: " + str);
            }
            i++;
            break;
          case 'b':
            try {
              str = args[i + 1].toLowerCase();
              int p = str.length();
              if (str.endsWith("k")) {
                transferSize = Integer.parseInt(str.substring(0, p - 1)) * 1024;
              } else if (str.endsWith("m")) {
                transferSize = Integer.parseInt(str.substring(0, p - 1)) * 1024 * 1024;
              } else {
                transferSize = Integer.parseInt(str);
              }
              i++;
            } catch (Exception e) {
              System.out.println("Bad number: " + str);
            }
        }
      } else {
        inputfilename = args[i];
      }
    }

    File inputfile = new File(inputfilename);
    if (!inputfile.exists() || !inputfile.isFile()) {
      System.out.println("Can not read " + inputfilename);
      System.exit(1);
    }

    if (sameoutput || outputfilename.equals("")) {
      outputfilename = inputfilename + ".xnd";
    }

    if (VERBOSE > 0) {
      String info =
          ""
              + "File to upload:\t\t"
              + inputfilename
              + "\n"
              + "Output file:\t\t"
              + outputfilename
              + "\n"
              + "Number of copies:\t"
              + copies
              + "\n"
              + "Max depots requested:\t"
              + maxDepots
              + "\n"
              + "Duration:\t\t"
              + duration
              + " sec.\n"
              + "Transfer size:\t\t"
              + transferSize
              + " bytes\n"
              + "Number of connections:\t"
              + connections
              + "\n"
              + "Location:\t\t"
              + location
              + "\n";

      System.out.println(info);
    }

    LogisticalUpload lu = new LogisticalUpload();
    lu.fill_LBoneServerList("", 0);
    lu.upload(
        inputfile,
        outputfilename,
        copies,
        maxDepots,
        duration,
        transferSize,
        connections,
        location);
  }