mirror of https://github.com/zlatinb/muwire
explicitly use longs
parent
858c223b4c
commit
82cc664fa2
|
@ -3,7 +3,7 @@ package com.muwire.core
|
||||||
class FileHasher {
|
class FileHasher {
|
||||||
|
|
||||||
/** max size of shared file is 128 GB */
|
/** max size of shared file is 128 GB */
|
||||||
public static final long MAX_SIZE = 0x1 << 37
|
public static final long MAX_SIZE = 0x1L << 37
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param size of the file to be shared
|
* @param size of the file to be shared
|
||||||
|
@ -14,7 +14,7 @@ class FileHasher {
|
||||||
return 18
|
return 18
|
||||||
|
|
||||||
for (int i = 26; i <= 37; i++) {
|
for (int i = 26; i <= 37; i++) {
|
||||||
if (size <= 0x1 << i) {
|
if (size <= 0x1L << i) {
|
||||||
return i-7
|
return i-7
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ class FileHasherTest extends GroovyTestCase {
|
||||||
void testPieceSize() {
|
void testPieceSize() {
|
||||||
assert 18 == FileHasher.getPieceSize(1000000)
|
assert 18 == FileHasher.getPieceSize(1000000)
|
||||||
assert 20 == FileHasher.getPieceSize(100000000)
|
assert 20 == FileHasher.getPieceSize(100000000)
|
||||||
|
assert 30 == FileHasher.getPieceSize(FileHasher.MAX_SIZE)
|
||||||
shouldFail IllegalArgumentException, {
|
shouldFail IllegalArgumentException, {
|
||||||
FileHasher.getPieceSize(Long.MAX_VALUE)
|
FileHasher.getPieceSize(Long.MAX_VALUE)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue