Android Code Snippet Get CRC32 from File

Discussion in 'Code Snippets' started by wonder, Apr 20, 2019.

Tags:
  1. wonder

    wonder Expert Licensed User

    Libs:
    - Reflection
    - FastIO (ProBundle)
    - ByteConverter
    Code:
    Sub CRC32(filename As StringAs String
        
    Dim r As Reflector
        
    Dim io As FastIO
        
    Dim bc As ByteConverter
        
    Dim data() = io.ReadArray(filename, 1024As 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: Apr 30, 2019
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice