Md5Util.smali

.class public Lcom/cmcm/support/base/Md5Util;
.super Ljava/lang/Object;


# direct methods
.method public constructor <init>()V
    .registers 1

    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    return-void
.end method

.method public static getFileMD5(Ljava/io/File;)Ljava/lang/String;
    .registers 8

    const/16 v2, 0x400

    const/4 v0, 0x0

    invoke-virtual {p0}, Ljava/io/File;->isFile()Z

    move-result v1

    if-nez v1, :cond_a

    :cond_9
    :goto_9
    return-object v0

    :cond_a
    new-array v2, v2, [B

    :try_start_c
    const-string/jumbo v1, "MD5"

    invoke-static {v1}, Ljava/security/MessageDigest;->getInstance(Ljava/lang/String;)Ljava/security/MessageDigest;

    move-result-object v3

    new-instance v1, Ljava/io/FileInputStream;

    invoke-direct {v1, p0}, Ljava/io/FileInputStream;-><init>(Ljava/io/File;)V
    :try_end_18
    .catch Ljava/lang/Exception; {:try_start_c .. :try_end_18} :catch_48
    .catchall {:try_start_c .. :try_end_18} :catchall_3c

    :goto_18
    const/4 v4, 0x0

    const/16 v5, 0x400

    :try_start_1b
    invoke-virtual {v1, v2, v4, v5}, Ljava/io/FileInputStream;->read([BII)I

    move-result v4

    const/4 v5, -0x1

    if-eq v4, v5, :cond_2e

    const/4 v5, 0x0

    invoke-virtual {v3, v2, v5, v4}, Ljava/security/MessageDigest;->update([BII)V
    :try_end_26
    .catch Ljava/lang/Exception; {:try_start_1b .. :try_end_26} :catch_27
    .catchall {:try_start_1b .. :try_end_26} :catchall_46

    goto :goto_18

    :catch_27
    move-exception v2

    :goto_28
    if-eqz v1, :cond_9

    invoke-virtual {v1}, Ljava/io/FileInputStream;->close()V

    goto :goto_9

    :cond_2e
    if-eqz v1, :cond_33

    invoke-virtual {v1}, Ljava/io/FileInputStream;->close()V

    :cond_33
    invoke-virtual {v3}, Ljava/security/MessageDigest;->digest()[B

    move-result-object v0

    invoke-static {v0}, Lcom/cmcm/support/base/StringUtil;->toHexString([B)Ljava/lang/String;

    move-result-object v0

    goto :goto_9

    :catchall_3c
    move-exception v1

    move-object v6, v1

    move-object v1, v0

    move-object v0, v6

    :goto_40
    if-eqz v1, :cond_45

    invoke-virtual {v1}, Ljava/io/FileInputStream;->close()V

    :cond_45
    throw v0

    :catchall_46
    move-exception v0

    goto :goto_40

    :catch_48
    move-exception v1

    move-object v1, v0

    goto :goto_28
.end method

.method public static getFileMD5Bytes(Ljava/io/File;)[B
    .registers 8

    const/16 v2, 0x400

    const/4 v0, 0x0

    invoke-virtual {p0}, Ljava/io/File;->isFile()Z

    move-result v1

    if-eqz v1, :cond_f

    invoke-virtual {p0}, Ljava/io/File;->exists()Z

    move-result v1

    if-nez v1, :cond_10

    :cond_f
    :goto_f
    return-object v0

    :cond_10
    new-array v2, v2, [B

    :try_start_12
    const-string/jumbo v1, "MD5"

    invoke-static {v1}, Ljava/security/MessageDigest;->getInstance(Ljava/lang/String;)Ljava/security/MessageDigest;

    move-result-object v3

    new-instance v1, Ljava/io/FileInputStream;

    invoke-direct {v1, p0}, Ljava/io/FileInputStream;-><init>(Ljava/io/File;)V
    :try_end_1e
    .catch Ljava/lang/Exception; {:try_start_12 .. :try_end_1e} :catch_52
    .catchall {:try_start_12 .. :try_end_1e} :catchall_42

    :goto_1e
    const/4 v4, 0x0

    const/16 v5, 0x400

    :try_start_21
    invoke-virtual {v1, v2, v4, v5}, Ljava/io/FileInputStream;->read([BII)I

    move-result v4

    const/4 v5, -0x1

    if-eq v4, v5, :cond_36

    const/4 v5, 0x0

    invoke-virtual {v3, v2, v5, v4}, Ljava/security/MessageDigest;->update([BII)V
    :try_end_2c
    .catch Ljava/lang/Exception; {:try_start_21 .. :try_end_2c} :catch_2d
    .catchall {:try_start_21 .. :try_end_2c} :catchall_50

    goto :goto_1e

    :catch_2d
    move-exception v2

    :goto_2e
    if-eqz v1, :cond_f

    :try_start_30
    invoke-virtual {v1}, Ljava/io/FileInputStream;->close()V
    :try_end_33
    .catch Ljava/io/IOException; {:try_start_30 .. :try_end_33} :catch_34

    goto :goto_f

    :catch_34
    move-exception v1

    goto :goto_f

    :cond_36
    if-eqz v1, :cond_3b

    :try_start_38
    invoke-virtual {v1}, Ljava/io/FileInputStream;->close()V
    :try_end_3b
    .catch Ljava/io/IOException; {:try_start_38 .. :try_end_3b} :catch_4c

    :cond_3b
    :goto_3b
    if-eqz v3, :cond_f

    invoke-virtual {v3}, Ljava/security/MessageDigest;->digest()[B

    move-result-object v0

    goto :goto_f

    :catchall_42
    move-exception v1

    move-object v6, v1

    move-object v1, v0

    move-object v0, v6

    :goto_46
    if-eqz v1, :cond_4b

    :try_start_48
    invoke-virtual {v1}, Ljava/io/FileInputStream;->close()V
    :try_end_4b
    .catch Ljava/io/IOException; {:try_start_48 .. :try_end_4b} :catch_4e

    :cond_4b
    :goto_4b
    throw v0

    :catch_4c
    move-exception v1

    goto :goto_3b

    :catch_4e
    move-exception v1

    goto :goto_4b

    :catchall_50
    move-exception v0

    goto :goto_46

    :catch_52
    move-exception v1

    move-object v1, v0

    goto :goto_2e
.end method

.method public static getStreamMD5(Ljava/io/InputStream;)Ljava/lang/String;
    .registers 5

    if-nez p0, :cond_6

    const-string/jumbo v0, ""

    :goto_5
    return-object v0

    :cond_6
    const/16 v0, 0x400

    new-array v0, v0, [B

    const-string/jumbo v1, ""

    const-string/jumbo v1, "MD5"

    invoke-static {v1}, Ljava/security/MessageDigest;->getInstance(Ljava/lang/String;)Ljava/security/MessageDigest;

    move-result-object v1

    :goto_14
    invoke-virtual {p0, v0}, Ljava/io/InputStream;->read([B)I

    move-result v2

    if-lez v2, :cond_1f

    const/4 v3, 0x0

    invoke-virtual {v1, v0, v3, v2}, Ljava/security/MessageDigest;->update([BII)V

    goto :goto_14

    :cond_1f
    invoke-virtual {v1}, Ljava/security/MessageDigest;->digest()[B

    move-result-object v0

    invoke-static {v0}, Lcom/cmcm/support/base/Md5Test;->bufferToHex([B)Ljava/lang/String;

    move-result-object v0

    invoke-virtual {p0}, Ljava/io/InputStream;->close()V

    goto :goto_5
.end method