1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| public void generatePieceHashes(TorrentFile torr) {
ByteBuffer bb = ByteBuffer.allocate(torr.pieceLength);
int index = 0;
long total = 0;
torr.piece_hash_values_as_binary.clear();
for (int i = 0; i < torr.name.size(); i++) {
total += (Integer) torr.length.get(i);//
File f = new File((String) torr.name.get(i));
if (f.exists()) {
try {
FileInputStream fis = new FileInputStream(f);
int read = 0;
byte[] data = new byte[torr.pieceLength];
while ((read = fis.read(data, 0, bb.remaining())) != -1) {
bb.put(data, 0, read);
if (bb.remaining() == 0) {
torr.piece_hash_values_as_binary.add(Utils.hash(bb.
array()));
bb.clear(); // L erreur est ici
}
}
} catch (FileNotFoundException fnfe) {} catch (IOException ioe) {}
}
}
if (bb.remaining() != bb.capacity())
torr.piece_hash_values_as_binary.add(Utils.hash(Utils.subArray(
bb.array(), 0, bb.capacity() - bb.remaining())));
} |
Partager