Fix Checksum calculate() with special characters

(cherry picked from commit e9efd5a702)
This commit is contained in:
FOCONIS\szemenyei
2022-01-11 09:47:44 +01:00
parent 18eed47306
commit 8d85000970
3 changed files with 5 additions and 4 deletions
@@ -1,6 +1,7 @@
package io.ebeaninternal.dbmigration;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.zip.CRC32;
@@ -13,9 +14,8 @@ class MChecksum {
* Returns the checksum of the file. Agnostic of encoding and new line character.
*/
static int calculate(File file) {
try {
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8")))) {
final CRC32 crc32 = new CRC32();
BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
String line;
while ((line = bufferedReader.readLine()) != null) {
final byte[] lineBytes = line.getBytes(StandardCharsets.UTF_8);
@@ -10,9 +10,9 @@ public class MChecksumTest {
@Test
public void calculate() {
File file = new File("src/test/resources/dbmigration/index/1.0__hello.sql");
File file = new File("src/test/resources/dbmigration/index-special-chars/1.0__hello.sql");
assertThat(file).exists();
assertThat(MChecksum.calculate(file)).isEqualTo(907060870);
assertThat(MChecksum.calculate(file)).isEqualTo(1859426839);
}
}