public TorrentFileSystemMemento toMemento() {
   TorrentFileSystemMemento memento = new TorrentFileSystemMementoImpl();
   memento.setCompleteFile(_completeFile);
   List<TorrentFile> files;
   Collection<File> folders;
   synchronized (this) {
     files = new ArrayList<TorrentFile>(_files);
     folders = new HashSet<File>(_folders);
   }
   memento.setFiles(files);
   memento.setFolders(folders);
   memento.setIncompleteFile(_incompleteFile);
   memento.setName(_name);
   memento.setTotalSize(_totalSize);
   return memento;
 }
  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();
  }