Android Code Snippet Get CRC32 from File

Libs:
- Reflection
- FastIO (ProBundle)
- ByteConverter
B4X:
Sub CRC32(filename As String) As String
    Dim r As Reflector
    Dim io As FastIO
    Dim bc As ByteConverter
    Dim data() = io.ReadArray(filename, 1024) As Byte
    r.Target = r.CreateObject("java.util.zip.CRC32")
    r.RunMethod4("update", Array As Object(data), Array As String("[B"))
    Dim CRCLong = r.RunMethod("getValue") As Long
    Dim CRCBytes() = bc.LongsToBytes(Array As Long(CRCLong)) As Byte
    Dim hex = bc.HexFromBytes(CRCBytes) As String
    Return hex.SubString(8) 'Removes the leading zeroes
End Sub

Based on Erel's code. :)
 
Last edited:
Top