mirror of https://github.com/zlatinb/muwire
retry hashing if an internal error happens
parent
cb204a6c79
commit
5365285e73
|
@ -2,7 +2,7 @@ package com.muwire.core.files
|
|||
|
||||
import com.muwire.core.InfoHash
|
||||
import com.muwire.core.util.DataUtil
|
||||
|
||||
import groovy.util.logging.Log
|
||||
import net.i2p.data.Base64
|
||||
|
||||
import java.nio.MappedByteBuffer
|
||||
|
@ -11,7 +11,9 @@ import java.nio.channels.FileChannel.MapMode
|
|||
import java.nio.channels.FileLock
|
||||
import java.security.MessageDigest
|
||||
import java.security.NoSuchAlgorithmException
|
||||
import java.util.logging.Level
|
||||
|
||||
@Log
|
||||
class FileHasher {
|
||||
|
||||
public static final int MIN_PIECE_SIZE_POW2 = 17
|
||||
|
@ -50,6 +52,8 @@ class FileHasher {
|
|||
}
|
||||
|
||||
InfoHash hashFile(File file) {
|
||||
while(true) {
|
||||
try {
|
||||
final long length = file.length()
|
||||
final long size = 0x1L << getPieceSize(length)
|
||||
int numPieces = (length / size).toInteger()
|
||||
|
@ -77,7 +81,12 @@ class FileHasher {
|
|||
}
|
||||
|
||||
byte[] hashList = output.toByteArray()
|
||||
InfoHash.fromHashList(hashList)
|
||||
return InfoHash.fromHashList(hashList)
|
||||
} catch (InternalError bad) {
|
||||
// nothing we can but try again. Happens on jre 18.0.1
|
||||
log.log(Level.SEVERE,"internal error while hashing", bad)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
|
Loading…
Reference in New Issue