Ejemplo n.º 1
0
  protected void constructFixed(File _torrent_base, long _piece_length) throws TOTorrentException {

    setIgnoreList();

    setCreationDate(SystemTime.getCurrentTime() / 1000);

    setCreatedBy(Constants.AZUREUS_NAME + "/" + Constants.AZUREUS_VERSION);

    setPieceLength(_piece_length);

    report("Torrent.create.progress.piecelength", _piece_length);

    piece_count = calculateNumberOfPieces(_torrent_base, _piece_length);

    if (piece_count == 0) {

      throw (new TOTorrentException(
          "TOTorrentCreate: specified files have zero total length",
          TOTorrentException.RT_ZERO_LENGTH));
    }

    report("Torrent.create.progress.hashing");

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

      ((TOTorrentProgressListener) progress_listeners.get(i)).reportProgress(0);
    }

    boolean add_other_per_file_hashes = add_other_hashes && !getSimpleTorrent();

    file_hasher =
        new TOTorrentFileHasher(
            add_other_hashes,
            add_other_per_file_hashes,
            (int) _piece_length,
            progress_listeners.size() == 0 ? null : this);

    if (cancelled) {

      throw (new TOTorrentException(
          "TOTorrentCreate: operation cancelled", TOTorrentException.RT_CANCELLED));
    }

    if (getSimpleTorrent()) {

      long length = file_hasher.add(_torrent_base);

      setFiles(
          new TOTorrentFileImpl[] {
            new TOTorrentFileImpl(this, 0, length, new byte[][] {getName()})
          });

      setPieces(file_hasher.getPieces());

    } else {

      Vector encoded = new Vector();

      processDir(file_hasher, _torrent_base, encoded, "");

      TOTorrentFileImpl[] files = new TOTorrentFileImpl[encoded.size()];

      encoded.copyInto(files);

      setFiles(files);
    }

    setPieces(file_hasher.getPieces());

    if (add_other_hashes) {

      byte[] sha1_digest = file_hasher.getSHA1Digest();
      byte[] ed2k_digest = file_hasher.getED2KDigest();

      addAdditionalInfoProperty("sha1", sha1_digest);
      addAdditionalInfoProperty("ed2k", ed2k_digest);

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