public synchronized void init() throws IOException {
		int nPieces = new Double(Math.ceil((double)this.totalLength /
					this.pieceLength)).intValue();
		this.pieces = new Piece[nPieces];
		this.completedPieces = new BitSet(nPieces);

		this.piecesHashes.clear();

		logger.debug("Analyzing local data for " + this.getName() + "...");
		for (int idx=0; idx<this.pieces.length; idx++) {
			byte[] hash = new byte[Torrent.PIECE_HASH_SIZE];
			this.piecesHashes.get(hash);

			// The last piece may be shorter than the torrent's global piece
			// length.
			// tzn: yes might be, but if it isn't this will be 0, leading to no validation
			/*int len = (idx < this.pieces.length - 1) ?
				 this.pieceLength :
				 this.totalLength % this.pieceLength;*/
			int len = (idx < this.pieces.length - 1) ? 
					this.pieceLength :
					this.totalLength - ((this.pieces.length-1)*this.pieceLength);
			int off = idx * this.pieceLength;
			
			logger.trace("Creating Piece#" + idx + "/" + this.pieces.length + " off: " + off + " len: " + len + "/" + this.totalLength + " bytes " + len*idx + ")");

			this.pieces[idx] = new Piece(this.bucket, idx, off, len, hash);
			this.pieces[idx].validate();
			if (this.pieces[idx].isValid()) {
				this.completedPieces.set(idx);
				this.left -= len;
			}
		}

		logger.debug(this.getName() + ": " +
				(this.totalLength - this.left) + "/" +
				this.totalLength + " bytes [" +
				this.completedPieces.cardinality() + "/" +
				this.pieces.length + "].");
	}