-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
746a0f3
commit be0f2d2
Showing
7 changed files
with
81 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/ru/olegcherednik/zip4jvm/utils/ChecksumUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package ru.olegcherednik.zip4jvm.utils; | ||
|
||
import ru.olegcherednik.zip4jvm.utils.quitely.Quietly; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import org.apache.commons.codec.digest.PureJavaCrc32; | ||
import org.apache.commons.io.IOUtils; | ||
|
||
import java.io.BufferedInputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.zip.CheckedInputStream; | ||
import java.util.zip.Checksum; | ||
|
||
/** | ||
* @author Oleg Cherednik | ||
* @since 31.10.2024 | ||
*/ | ||
@NoArgsConstructor(access = AccessLevel.PACKAGE) | ||
public final class ChecksumUtils { | ||
|
||
@SuppressWarnings("NewMethodNamingConvention") | ||
public static long crc32(Path file) { | ||
return Quietly.doQuietly(() -> { | ||
Checksum crc32 = new PureJavaCrc32(); | ||
|
||
try (CheckedInputStream in = new CheckedInputStream( | ||
new BufferedInputStream(Files.newInputStream(file)), crc32)) { | ||
byte[] buf = new byte[1024]; | ||
|
||
while (in.read(buf) != IOUtils.EOF) { | ||
// read file in completely | ||
} | ||
} | ||
|
||
return crc32.getValue(); | ||
}); | ||
} | ||
|
||
} |