예제 #1
0
 /**
  * Updates the files in the specified collection to start at the new base path. The files must
  * already be absolute and be children of _completeFile.
  *
  * @param completeBase the new base path
  */
 private void updateReferences(File completeBase, List<TorrentFile> l) {
   int offset = _completeFile.getAbsolutePath().length();
   String newPath = completeBase.getAbsolutePath();
   for (int i = 0; i < l.size(); i++) {
     TorrentFile current = l.get(i);
     TorrentFile updated =
         new TorrentFile(
             current.length(),
             newPath + current.getPath().substring(offset),
             current.getTorrentPath());
     updated.setBeginPiece(current.getBeginPiece());
     updated.setEndPiece(current.getEndPiece());
     updated.setStartByte(current.getStartByte());
     updated.setEndByte(current.getEndByte());
     l.set(i, updated);
   }
 }
예제 #2
0
  public TorrentFileSystem(int numHashes, TorrentFileSystemMemento torrentFileSystemMemento) {
    this._name = torrentFileSystemMemento.getName();
    this._totalSize = torrentFileSystemMemento.getTotalSize();
    this._files = torrentFileSystemMemento.getFiles();

    // BEGIN TODO remove this code after releasing a few versions Sept 2nd 2008.
    // There was a bug, where the file end piece would be set to numhashes instead of numhashes-1
    // the piece index is zero based. old code used to ignore these propblems, some of the newer
    // code throws an illegal argument exception.
    for (TorrentFile file : _files) {
      if (file.getEndPiece() == numHashes) {
        file.setEndPiece(numHashes - 1);
      }
    }
    // END TODO

    this._unmodFiles = Collections.unmodifiableList(_files);
    _folders.addAll(torrentFileSystemMemento.getFolders());
    this._incompleteFile = torrentFileSystemMemento.getIncompleteFile();
    this._completeFile = torrentFileSystemMemento.getCompleteFile();
  }