コード例 #1
0
  protected static long getTorrentDataSizeFromFileOrDirSupport(File file) {
    String name = file.getName();

    if (name.equals(".") || name.equals("..")) {

      return (0);
    }

    if (!file.exists()) {

      return (0);
    }

    if (file.isFile()) {

      return (file.length());

    } else {

      File[] dir_files = file.listFiles();

      long length = 0;

      for (int i = 0; i < dir_files.length; i++) {

        length += getTorrentDataSizeFromFileOrDirSupport(dir_files[i]);
      }

      return (length);
    }
  }
コード例 #2
0
  protected TOTorrentCreateImpl(
      File _torrent_base, URL _announce_url, boolean _add_other_hashes, long _piece_length)
      throws TOTorrentException {
    super(_torrent_base.getName(), _announce_url, _torrent_base.isFile());

    torrent_base = _torrent_base;
    piece_length = _piece_length;
    add_other_hashes = _add_other_hashes;
  }
コード例 #3
0
  protected long getTotalFileSizeSupport(File file) throws TOTorrentException {

    String name = file.getName();

    /////////////////////////////////////////

    /////////////////////////////////////

    if (name.equals(".") || name.equals("..")) {

      return (0);
    }

    if (!file.exists()) {

      throw (new TOTorrentException(
          "TOTorrentCreate: file '" + file.getName() + "' doesn't exist",
          TOTorrentException.RT_FILE_NOT_FOUND));
    }

    if (file.isFile()) {

      if (!ignoreFile(name)) {

        total_file_count++;

        return (file.length());

      } else {

        return (0);
      }
    } else {

      File[] dir_files = file.listFiles();

      if (dir_files == null) {

        throw (new TOTorrentException(
            "TOTorrentCreate: directory '"
                + file.getAbsolutePath()
                + "' returned error when listing files in it",
            TOTorrentException.RT_FILE_NOT_FOUND));
      }

      long length = 0;

      for (int i = 0; i < dir_files.length; i++) {

        length += getTotalFileSizeSupport(dir_files[i]);
      }

      return (length);
    }
  }
コード例 #4
0
  protected TOTorrentCreateImpl(
      File _torrent_base,
      URL _announce_url,
      boolean _add_other_hashes,
      long _piece_min_size,
      long _piece_max_size,
      long _piece_num_lower,
      long _piece_num_upper)
      throws TOTorrentException {
    super(_torrent_base.getName(), _announce_url, _torrent_base.isFile());

    torrent_base = _torrent_base;
    add_other_hashes = _add_other_hashes;

    long total_size = calculateTotalFileSize(_torrent_base);

    piece_length =
        getComputedPieceSize(
            total_size, _piece_min_size, _piece_max_size, _piece_num_lower, _piece_num_upper);
  }