mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-12 22:41:35 +00:00
Change Checksum to use CRC32
This commit is contained in:
1 parent
991c6d6b5c
commit
0d8e7c852b
2 files changed
+12
-7
No files matched your search
@@ -1,7 +1,7 @@
|
||||
package io.ebeaninternal.server.util;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.zip.Adler32;
|
||||
import java.util.zip.CRC32;
|
||||
|
||||
/**
|
||||
* Compute a checksum for String content. Use when we desire cheaper option than MD5.
|
||||
@@ -12,9 +12,9 @@ public final class Checksum {
|
||||
* Return the checksum for the given String input.
|
||||
*/
|
||||
public static long checksum(String input) {
|
||||
Adler32 adler32 = new Adler32();
|
||||
CRC32 checksum = new CRC32();
|
||||
final byte[] bytes = input.getBytes(StandardCharsets.UTF_8);
|
||||
adler32.update(bytes, 0, bytes.length);
|
||||
return adler32.getValue();
|
||||
checksum.update(bytes, 0, bytes.length);
|
||||
return checksum.getValue();
|
||||
}
|
||||
}
|
||||
@@ -8,11 +8,16 @@ public class ChecksumTest {
|
||||
|
||||
@Test
|
||||
public void checksum() {
|
||||
|
||||
final long val = Checksum.checksum("Hello world");
|
||||
assertThat(val).isEqualTo(413860925L);
|
||||
|
||||
assertThat(val).isEqualTo(2346098258L);
|
||||
assertThat(Checksum.checksum("Hello world")).isEqualTo(val);
|
||||
assertThat(Checksum.checksum("hello world")).isNotEqualTo(val);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checksum_shortString() {
|
||||
final long val0 = Checksum.checksum("2012-01-11");
|
||||
final long val1 = Checksum.checksum("2012-10-02");
|
||||
assertThat(val0).isNotEqualTo(val1);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user