use standard buffer size for Utils.getBinaryHash()
While a large buffer might make things slightly faster, the smaller buffer size should play much nicer when F-Droid is doing things in the background. Since calculating the hash is part of the update procedure, which can now happen in the background, this method will be often running in the background. The tests showed no difference in time between the large and small buffer.
This commit is contained in:
parent
a09b1ecb58
commit
55aa8e9aa6
@ -409,7 +409,7 @@ public final class Utils {
|
|||||||
fis = new FileInputStream(apk);
|
fis = new FileInputStream(apk);
|
||||||
BufferedInputStream bis = new BufferedInputStream(fis);
|
BufferedInputStream bis = new BufferedInputStream(fis);
|
||||||
|
|
||||||
byte[] dataBytes = new byte[524288];
|
byte[] dataBytes = new byte[8192];
|
||||||
int nread;
|
int nread;
|
||||||
while ((nread = bis.read(dataBytes)) != -1) {
|
while ((nread = bis.read(dataBytes)) != -1) {
|
||||||
md.update(dataBytes, 0, nread);
|
md.update(dataBytes, 0, nread);
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
package org.fdroid.fdroid;
|
package org.fdroid.fdroid;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import org.fdroid.fdroid.views.AppDetailsRecyclerViewAdapter;
|
import org.fdroid.fdroid.views.AppDetailsRecyclerViewAdapter;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -10,6 +9,8 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
@ -174,6 +175,21 @@ public class UtilsTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetBinaryHash() {
|
||||||
|
File f = TestUtils.copyResourceToTempFile("largeRepo.xml");
|
||||||
|
assertEquals("df1754aa4b56c86c06d7842dfd02064f0781c1f740f489d3fc158bb541c8d197",
|
||||||
|
Utils.getBinaryHash(f, "sha256"));
|
||||||
|
f = TestUtils.copyResourceToTempFile("masterKeyIndex.jar");
|
||||||
|
assertEquals("625d5aedcd0499fe04ebab81f3c7ae30c236cee653a914ffb587d890198f3aba",
|
||||||
|
Utils.getBinaryHash(f, "sha256"));
|
||||||
|
f = TestUtils.copyResourceToTempFile("index.fdroid.2016-10-30.jar");
|
||||||
|
assertEquals("c138b503c6475aa749585d0e3ad4dba3546b6d33ec485efd8ac8bd603d93fedb",
|
||||||
|
Utils.getBinaryHash(f, "sha256"));
|
||||||
|
f = TestUtils.copyResourceToTempFile("index.fdroid.2016-11-10.jar");
|
||||||
|
assertEquals("93bea45814fd8955cabb957e7a3f8790d6c568eaa16fa30425c2d26c60490bde",
|
||||||
|
Utils.getBinaryHash(f, "sha256"));
|
||||||
|
}
|
||||||
// TODO write tests that work with a Certificate
|
// TODO write tests that work with a Certificate
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user