StatisFileUtils.smali

.class public Lsg/bigo/sdk/blivestat/utils/StatisFileUtils;
.super Ljava/lang/Object;
.source "SourceFile"


# static fields
.field private static final MAX_LENGTH:I = 0x500000

.field public static final STATSDK_CACHE_INFO_FILE_NAME:Ljava/lang/String; = "statsdk_cache_info_file_v2tcp"

.field public static final STATSDK_CACHE_INFO_FILE_NAME_CONFIG:Ljava/lang/String; = "statsdk_cache_info_file_v2"

.field private static final STATSDK_CACHE_USE_TIME_FILE_NAME:Ljava/lang/String; = "statsdk_use_time_info"

.field private static final TAG:Ljava/lang/String; = "BLiveStatisSDK"


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

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

    return-void
.end method

.method private static covertByteArrayToInt([B)I
    .registers 4

    const/4 v0, 0x0

    if-eqz p0, :cond_17

    .line 252
    array-length v1, p0

    const/4 v2, 0x4

    if-ge v1, v2, :cond_8

    goto :goto_17

    .line 255
    :cond_8
    invoke-static {p0, v0, v2}, Ljava/nio/ByteBuffer;->wrap([BII)Ljava/nio/ByteBuffer;

    move-result-object p0

    sget-object v0, Ljava/nio/ByteOrder;->BIG_ENDIAN:Ljava/nio/ByteOrder;

    .line 256
    invoke-virtual {p0, v0}, Ljava/nio/ByteBuffer;->order(Ljava/nio/ByteOrder;)Ljava/nio/ByteBuffer;

    move-result-object p0

    .line 257
    invoke-virtual {p0}, Ljava/nio/ByteBuffer;->getInt()I

    move-result p0

    return p0

    :cond_17
    :goto_17
    return v0
.end method

.method private static covertIntToByteArray(I)[B
    .registers 3

    const/4 v0, 0x4

    .line 241
    invoke-static {v0}, Ljava/nio/ByteBuffer;->allocate(I)Ljava/nio/ByteBuffer;

    move-result-object v0

    sget-object v1, Ljava/nio/ByteOrder;->BIG_ENDIAN:Ljava/nio/ByteOrder;

    .line 242
    invoke-virtual {v0, v1}, Ljava/nio/ByteBuffer;->order(Ljava/nio/ByteOrder;)Ljava/nio/ByteBuffer;

    move-result-object v0

    .line 243
    invoke-virtual {v0, p0}, Ljava/nio/ByteBuffer;->putInt(I)Ljava/nio/ByteBuffer;

    move-result-object p0

    .line 244
    invoke-virtual {p0}, Ljava/nio/ByteBuffer;->array()[B

    move-result-object p0

    return-object p0
.end method

.method public static deleteCacheFile(Landroid/content/Context;Ljava/lang/String;)Z
    .registers 3

    .line 70
    new-instance v0, Ljava/io/File;

    invoke-virtual {p0}, Landroid/content/Context;->getFilesDir()Ljava/io/File;

    move-result-object p0

    invoke-direct {v0, p0, p1}, Ljava/io/File;-><init>(Ljava/io/File;Ljava/lang/String;)V

    .line 71
    invoke-static {v0}, Lsg/bigo/common/l;->b(Ljava/io/File;)Z

    move-result p0

    return p0
.end method

.method public static getUseTimeCacheFilename(Ljava/lang/String;I)Ljava/lang/String;
    .registers 4

    .line 54
    new-instance v0, Ljava/lang/StringBuilder;

    const-string v1, "statsdk_use_time_info_"

    invoke-direct {v0, v1}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v0, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    const-string p0, "_"

    invoke-virtual {v0, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    invoke-virtual {v0, p1}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object p0

    return-object p0
.end method

.method public static loadCacheByteDataFromFile(Landroid/content/Context;Ljava/lang/String;)Ljava/util/LinkedList;
    .registers 14
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Landroid/content/Context;",
            "Ljava/lang/String;",
            ")",
            "Ljava/util/LinkedList<",
            "[B>;"
        }
    .end annotation

    .line 172
    new-instance v0, Ljava/util/LinkedList;

    invoke-direct {v0}, Ljava/util/LinkedList;-><init>()V

    if-nez p0, :cond_8

    return-object v0

    .line 176
    :cond_8
    new-instance v1, Ljava/io/File;

    invoke-virtual {p0}, Landroid/content/Context;->getFilesDir()Ljava/io/File;

    move-result-object p0

    invoke-direct {v1, p0, p1}, Ljava/io/File;-><init>(Ljava/io/File;Ljava/lang/String;)V

    .line 177
    invoke-virtual {v1}, Ljava/io/File;->exists()Z

    move-result p0

    if-nez p0, :cond_18

    return-object v0

    :cond_18
    const/4 p0, 0x0

    const/4 p1, 0x0

    .line 188
    :try_start_1a
    new-instance v2, Ljava/io/FileInputStream;

    invoke-virtual {v1}, Ljava/io/File;->getAbsolutePath()Ljava/lang/String;

    move-result-object v3

    invoke-direct {v2, v3}, Ljava/io/FileInputStream;-><init>(Ljava/lang/String;)V
    :try_end_23
    .catch Ljava/lang/Exception; {:try_start_1a .. :try_end_23} :catch_6f
    .catchall {:try_start_1a .. :try_end_23} :catchall_66

    .line 189
    :try_start_23
    invoke-virtual {v1}, Ljava/io/File;->length()J

    move-result-wide v3

    const/4 p0, 0x1

    const/4 v5, 0x1

    :goto_29
    if-eqz v5, :cond_5c

    const/4 v6, 0x4

    new-array v7, v6, [B

    .line 192
    invoke-virtual {v2, v7, p1, v6}, Ljava/io/InputStream;->read([BII)I

    move-result v6

    const/4 v8, -0x1

    if-eq v6, v8, :cond_5a

    .line 194
    invoke-static {v7}, Lsg/bigo/sdk/blivestat/utils/StatisFileUtils;->covertByteArrayToInt([B)I

    move-result v6

    const-wide/16 v9, 0x4

    sub-long/2addr v3, v9

    if-lez v6, :cond_5c

    int-to-long v9, v6

    cmp-long v7, v3, v9

    if-ltz v7, :cond_5c

    const/high16 v7, 0x500000

    if-le v6, v7, :cond_49

    const/4 p1, 0x1

    goto :goto_5c

    .line 206
    :cond_49
    new-array v7, v6, [B

    .line 207
    invoke-virtual {v2, v7, p1, v6}, Ljava/io/InputStream;->read([BII)I

    move-result v11

    if-eq v11, v8, :cond_57

    if-ne v11, v6, :cond_57

    .line 209
    invoke-virtual {v0, v7}, Ljava/util/LinkedList;->add(Ljava/lang/Object;)Z
    :try_end_56
    .catch Ljava/lang/Exception; {:try_start_23 .. :try_end_56} :catch_64
    .catchall {:try_start_23 .. :try_end_56} :catchall_62

    goto :goto_58

    :cond_57
    const/4 v5, 0x0

    :goto_58
    sub-long/2addr v3, v9

    goto :goto_29

    :cond_5a
    const/4 v5, 0x0

    goto :goto_29

    .line 223
    :cond_5c
    :goto_5c
    :try_start_5c
    invoke-virtual {v2}, Ljava/io/InputStream;->close()V
    :try_end_5f
    .catch Ljava/io/IOException; {:try_start_5c .. :try_end_5f} :catch_60

    goto :goto_74

    :catch_60
    nop

    goto :goto_74

    :catchall_62
    move-exception p0

    goto :goto_69

    :catch_64
    move-object p0, v2

    goto :goto_6f

    :catchall_66
    move-exception p1

    move-object v2, p0

    move-object p0, p1

    :goto_69
    if-eqz v2, :cond_6e

    :try_start_6b
    invoke-virtual {v2}, Ljava/io/InputStream;->close()V
    :try_end_6e
    .catch Ljava/io/IOException; {:try_start_6b .. :try_end_6e} :catch_6e

    .line 227
    :catch_6e
    :cond_6e
    throw p0

    :catch_6f
    :goto_6f
    if-eqz p0, :cond_74

    .line 223
    :try_start_71
    invoke-virtual {p0}, Ljava/io/InputStream;->close()V
    :try_end_74
    .catch Ljava/io/IOException; {:try_start_71 .. :try_end_74} :catch_60

    :cond_74
    :goto_74
    if-eqz p1, :cond_80

    .line 231
    invoke-virtual {v1}, Ljava/io/File;->delete()Z

    const-string p0, "BLiveStatisSDK"

    const-string p1, "loadCacheByteDataFromFile too largeLength"

    .line 232
    invoke-static {p0, p1}, Lsg/bigo/sdk/blivestat/log/StatLog;->e(Ljava/lang/String;Ljava/lang/String;)V

    :cond_80
    return-object v0
.end method

.method public static readDataFromFile(Landroid/content/Context;Ljava/lang/String;)Ljava/lang/String;
    .registers 3

    .line 61
    new-instance v0, Ljava/io/File;

    invoke-virtual {p0}, Landroid/content/Context;->getFilesDir()Ljava/io/File;

    move-result-object p0

    invoke-direct {v0, p0, p1}, Ljava/io/File;-><init>(Ljava/io/File;Ljava/lang/String;)V

    .line 62
    invoke-virtual {v0}, Ljava/io/File;->exists()Z

    move-result p0

    if-nez p0, :cond_12

    const-string p0, ""

    return-object p0

    .line 63
    :cond_12
    invoke-static {v0}, Lsg/bigo/common/l;->a(Ljava/io/File;)Ljava/lang/String;

    move-result-object p0

    return-object p0
.end method

.method public static saveByteArrayListToFile(Landroid/content/Context;Ljava/util/LinkedList;Ljava/lang/String;Z)V
    .registers 7
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Landroid/content/Context;",
            "Ljava/util/LinkedList<",
            "[B>;",
            "Ljava/lang/String;",
            "Z)V"
        }
    .end annotation

    if-eqz p0, :cond_69

    if-eqz p1, :cond_69

    .line 86
    invoke-static {p2}, Landroid/text/TextUtils;->isEmpty(Ljava/lang/CharSequence;)Z

    move-result v0

    if-eqz v0, :cond_b

    goto :goto_69

    :cond_b
    const/4 v0, 0x0

    .line 90
    new-instance v1, Ljava/io/File;

    invoke-virtual {p0}, Landroid/content/Context;->getFilesDir()Ljava/io/File;

    move-result-object p0

    invoke-direct {v1, p0, p2}, Ljava/io/File;-><init>(Ljava/io/File;Ljava/lang/String;)V

    .line 92
    :try_start_15
    invoke-virtual {v1}, Ljava/io/File;->exists()Z

    move-result p0

    if-nez p0, :cond_1e

    .line 93
    invoke-virtual {v1}, Ljava/io/File;->createNewFile()Z

    .line 95
    :cond_1e
    new-instance p0, Ljava/io/FileOutputStream;

    invoke-virtual {v1}, Ljava/io/File;->getAbsolutePath()Ljava/lang/String;

    move-result-object p2

    invoke-direct {p0, p2, p3}, Ljava/io/FileOutputStream;-><init>(Ljava/lang/String;Z)V
    :try_end_27
    .catch Ljava/lang/Exception; {:try_start_15 .. :try_end_27} :catch_63
    .catchall {:try_start_15 .. :try_end_27} :catchall_5c

    .line 97
    :try_start_27
    invoke-virtual {p1}, Ljava/util/LinkedList;->iterator()Ljava/util/Iterator;

    move-result-object p1

    const/4 p2, 0x0

    :goto_2c
    const/4 p3, 0x0

    :cond_2d
    invoke-interface {p1}, Ljava/util/Iterator;->hasNext()Z

    move-result v0

    if-eqz v0, :cond_4f

    invoke-interface {p1}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, [B

    .line 98
    array-length v1, v0

    .line 99
    invoke-static {v1}, Lsg/bigo/sdk/blivestat/utils/StatisFileUtils;->covertIntToByteArray(I)[B

    move-result-object v2

    .line 100
    invoke-virtual {p0, v2}, Ljava/io/OutputStream;->write([B)V

    .line 101
    invoke-virtual {p0, v0}, Ljava/io/OutputStream;->write([B)V

    add-int/2addr p3, v1

    add-int/lit8 p3, p3, 0x4

    const/16 v0, 0x4000

    if-le p3, v0, :cond_2d

    .line 105
    invoke-virtual {p0}, Ljava/io/OutputStream;->flush()V

    goto :goto_2c

    .line 109
    :cond_4f
    invoke-virtual {p0}, Ljava/io/OutputStream;->flush()V
    :try_end_52
    .catch Ljava/lang/Exception; {:try_start_27 .. :try_end_52} :catch_5a
    .catchall {:try_start_27 .. :try_end_52} :catchall_56

    .line 115
    :try_start_52
    invoke-virtual {p0}, Ljava/io/OutputStream;->close()V
    :try_end_55
    .catch Ljava/lang/Exception; {:try_start_52 .. :try_end_55} :catch_55

    :catch_55
    return-void

    :catchall_56
    move-exception p1

    move-object v0, p0

    move-object p0, p1

    goto :goto_5d

    :catch_5a
    move-object v0, p0

    goto :goto_63

    :catchall_5c
    move-exception p0

    :goto_5d
    if-eqz v0, :cond_62

    :try_start_5f
    invoke-virtual {v0}, Ljava/io/OutputStream;->close()V
    :try_end_62
    .catch Ljava/lang/Exception; {:try_start_5f .. :try_end_62} :catch_62

    .line 119
    :catch_62
    :cond_62
    throw p0

    :catch_63
    :goto_63
    if-eqz v0, :cond_69

    .line 115
    :try_start_65
    invoke-virtual {v0}, Ljava/io/OutputStream;->close()V
    :try_end_68
    .catch Ljava/lang/Exception; {:try_start_65 .. :try_end_68} :catch_69

    nop

    :catch_69
    :cond_69
    :goto_69
    return-void
.end method

.method public static saveByteArrayToFile(Landroid/content/Context;[BLjava/lang/String;Z)V
    .registers 6

    if-eqz p0, :cond_4c

    if-eqz p1, :cond_4c

    .line 136
    invoke-static {p2}, Landroid/text/TextUtils;->isEmpty(Ljava/lang/CharSequence;)Z

    move-result v0

    if-eqz v0, :cond_b

    goto :goto_4c

    :cond_b
    const/4 v0, 0x0

    .line 140
    new-instance v1, Ljava/io/File;

    invoke-virtual {p0}, Landroid/content/Context;->getFilesDir()Ljava/io/File;

    move-result-object p0

    invoke-direct {v1, p0, p2}, Ljava/io/File;-><init>(Ljava/io/File;Ljava/lang/String;)V

    .line 142
    :try_start_15
    invoke-virtual {v1}, Ljava/io/File;->exists()Z

    move-result p0

    if-nez p0, :cond_1e

    .line 143
    invoke-virtual {v1}, Ljava/io/File;->createNewFile()Z

    .line 145
    :cond_1e
    new-instance p0, Ljava/io/FileOutputStream;

    invoke-virtual {v1}, Ljava/io/File;->getAbsolutePath()Ljava/lang/String;

    move-result-object p2

    invoke-direct {p0, p2, p3}, Ljava/io/FileOutputStream;-><init>(Ljava/lang/String;Z)V
    :try_end_27
    .catch Ljava/lang/Exception; {:try_start_15 .. :try_end_27} :catch_46
    .catchall {:try_start_15 .. :try_end_27} :catchall_3f

    .line 146
    :try_start_27
    array-length p2, p1

    .line 147
    invoke-static {p2}, Lsg/bigo/sdk/blivestat/utils/StatisFileUtils;->covertIntToByteArray(I)[B

    move-result-object p2

    .line 148
    invoke-virtual {p0, p2}, Ljava/io/OutputStream;->write([B)V

    .line 149
    invoke-virtual {p0, p1}, Ljava/io/OutputStream;->write([B)V

    .line 150
    invoke-virtual {p0}, Ljava/io/OutputStream;->flush()V
    :try_end_35
    .catch Ljava/lang/Exception; {:try_start_27 .. :try_end_35} :catch_3d
    .catchall {:try_start_27 .. :try_end_35} :catchall_39

    .line 156
    :try_start_35
    invoke-virtual {p0}, Ljava/io/OutputStream;->close()V
    :try_end_38
    .catch Ljava/lang/Exception; {:try_start_35 .. :try_end_38} :catch_38

    :catch_38
    return-void

    :catchall_39
    move-exception p1

    move-object v0, p0

    move-object p0, p1

    goto :goto_40

    :catch_3d
    move-object v0, p0

    goto :goto_46

    :catchall_3f
    move-exception p0

    :goto_40
    if-eqz v0, :cond_45

    :try_start_42
    invoke-virtual {v0}, Ljava/io/OutputStream;->close()V
    :try_end_45
    .catch Ljava/lang/Exception; {:try_start_42 .. :try_end_45} :catch_45

    .line 160
    :catch_45
    :cond_45
    throw p0

    :catch_46
    :goto_46
    if-eqz v0, :cond_4c

    .line 156
    :try_start_48
    invoke-virtual {v0}, Ljava/io/OutputStream;->close()V
    :try_end_4b
    .catch Ljava/lang/Exception; {:try_start_48 .. :try_end_4b} :catch_4c

    nop

    :catch_4c
    :cond_4c
    :goto_4c
    return-void
.end method

.method public static saveStrToFile(Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;)V
    .registers 4

    .line 44
    new-instance v0, Ljava/io/File;

    invoke-virtual {p0}, Landroid/content/Context;->getFilesDir()Ljava/io/File;

    move-result-object p0

    invoke-direct {v0, p0, p2}, Ljava/io/File;-><init>(Ljava/io/File;Ljava/lang/String;)V

    .line 45
    invoke-static {v0}, Lsg/bigo/common/l;->f(Ljava/io/File;)Z

    .line 46
    invoke-static {p1}, Landroid/text/TextUtils;->isEmpty(Ljava/lang/CharSequence;)Z

    move-result p0

    if-eqz p0, :cond_2b

    .line 47
    new-instance p0, Ljava/lang/StringBuilder;

    const-string p1, "save data to file"

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

    invoke-virtual {p0, p2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    const-string p1, " error"

    invoke-virtual {p0, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    invoke-virtual {p0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object p0

    const-string p1, "BLiveStatisSDK"

    invoke-static {p1, p0}, Lsg/bigo/sdk/blivestat/log/StatLog;->e(Ljava/lang/String;Ljava/lang/String;)V

    return-void

    .line 49
    :cond_2b
    invoke-static {v0, p1}, Lsg/bigo/common/l;->a(Ljava/io/File;Ljava/lang/String;)Z

    return-void
.end method