public boolean equals(Object obj) {
    if (this == obj) {

      return true;
    }

    if (obj instanceof TorrentDownloaderImpl) {

      TorrentDownloaderImpl other = (TorrentDownloaderImpl) obj;

      if (other.getURL().equals(this.url.toString())) {

        File other_file = other.getFile();
        File this_file = file;

        if (other_file == this_file) {

          return (true);
        }

        if (other_file == null || this_file == null) {

          return (false);
        }

        return (other_file.getAbsolutePath().equals(this_file.getAbsolutePath()));

      } else {

        return false;
      }
    } else {
      return false;
    }
  }
Пример #2
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);
    }
  }
Пример #3
0
  protected void processDir(TOTorrentFileHasher hasher, File dir, Vector encoded, String root)
      throws TOTorrentException {
    File[] dir_file_list = dir.listFiles();

    if (dir_file_list == null) {

      throw (new TOTorrentException(
          "TOTorrentCreate: directory '"
              + dir.getAbsolutePath()
              + "' returned error when listing files in it",
          TOTorrentException.RT_FILE_NOT_FOUND));
    }
    // sort contents so that multiple encodes of a dir always
    // generate same torrent

    List file_list = new ArrayList(Arrays.asList(dir_file_list));

    Collections.sort(file_list);

    long offset = 0;

    for (int i = 0; i < file_list.size(); i++) {

      File file = (File) file_list.get(i);

      String file_name = file.getName();

      if (!(file_name.equals(".") || file_name.equals(".."))) {

        if (file.isDirectory()) {

          if (root.length() > 0) {

            file_name = root + File.separator + file_name;
          }

          processDir(hasher, file, encoded, file_name);

        } else {

          if (!ignoreFile(file_name)) {

            if (root.length() > 0) {

              file_name = root + File.separator + file_name;
            }

            long length = hasher.add(file);

            TOTorrentFileImpl tf = new TOTorrentFileImpl(this, offset, length, file_name);

            offset += length;

            if (add_other_hashes) {

              byte[] ed2k_digest = hasher.getPerFileED2KDigest();
              byte[] sha1_digest = hasher.getPerFileSHA1Digest();

              // System.out.println( "file:ed2k = " + ByteFormatter.nicePrint( ed2k_digest, true ));
              // System.out.println( "file:sha1 = " + ByteFormatter.nicePrint( sha1_digest, true ));

              tf.setAdditionalProperty("sha1", sha1_digest);
              tf.setAdditionalProperty("ed2k", ed2k_digest);
            }

            encoded.addElement(tf);
          }
        }
      }
    }
  }