Ejemplo n.º 1
0
 public void WritePiece(Piece piece)
 {
     // The piece goes to file...
     int pieceOnFile = 0;
     // Write the piece
     ((FileData)filesData[pieceOnFile]).so.Write(piece.PieceIndex, piece.PieceValues);
 }
Ejemplo n.º 2
0
 public Piece Read(int pieceIndex, int begin, int length)
 {
     if (pieceIndex >= numPieces)
         throw new FileException("Piece [" + pieceIndex.ToString() + "] out of index.");
     if ((length - begin) > PIECELENGTH)
         throw new FileException("The piece length is not so big.");
     // TODO: Check to see if we already have the piece
     // Check to see if the piece is on memory
     if (!PieceOnMemory(pieceIndex)) {
         // Load Piece
         LoadPiece(pieceIndex);
     }
     FilePiece filePiece = (FilePiece) loadedPieces[pieceIndex];
     Piece requestedPiece = new Piece(pieceIndex, begin, filePiece.Piece(begin, length));
     return requestedPiece;
 }