DiskLogStrategy$WriteHandler.smali
4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
.class Lcom/orhanobut/logger/DiskLogStrategy$WriteHandler;
.super Landroid/os/Handler;
.source "DiskLogStrategy.java"
# annotations
.annotation system Ldalvik/annotation/EnclosingClass;
value = Lcom/orhanobut/logger/DiskLogStrategy;
.end annotation
.annotation system Ldalvik/annotation/InnerClass;
accessFlags = 0x8
name = "WriteHandler"
.end annotation
# instance fields
.field private final folder:Ljava/lang/String;
.field private final maxFileSize:I
# direct methods
.method constructor <init>(Landroid/os/Looper;Ljava/lang/String;I)V
.locals 0
.line 34
invoke-direct {p0, p1}, Landroid/os/Handler;-><init>(Landroid/os/Looper;)V
.line 35
iput-object p2, p0, Lcom/orhanobut/logger/DiskLogStrategy$WriteHandler;->folder:Ljava/lang/String;
.line 36
iput p3, p0, Lcom/orhanobut/logger/DiskLogStrategy$WriteHandler;->maxFileSize:I
return-void
.end method
.method private getLogFile(Ljava/lang/String;Ljava/lang/String;)Ljava/io/File;
.locals 10
.line 76
new-instance v0, Ljava/io/File;
invoke-direct {v0, p1}, Ljava/io/File;-><init>(Ljava/lang/String;)V
.line 77
invoke-virtual {v0}, Ljava/io/File;->exists()Z
move-result p1
if-nez p1, :cond_0
.line 79
invoke-virtual {v0}, Ljava/io/File;->mkdirs()Z
:cond_0
const/4 p1, 0x0
.line 86
new-instance v1, Ljava/io/File;
const/4 v2, 0x2
new-array v3, v2, [Ljava/lang/Object;
const/4 v4, 0x0
aput-object p2, v3, v4
invoke-static {v4}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;
move-result-object v5
const/4 v6, 0x1
aput-object v5, v3, v6
const-string v5, "%s_%s.csv"
invoke-static {v5, v3}, Ljava/lang/String;->format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
move-result-object v3
invoke-direct {v1, v0, v3}, Ljava/io/File;-><init>(Ljava/io/File;Ljava/lang/String;)V
move v3, v4
:goto_0
move-object v9, v1
move-object v1, p1
move-object p1, v9
.line 87
invoke-virtual {p1}, Ljava/io/File;->exists()Z
move-result v7
if-eqz v7, :cond_1
add-int/2addr v3, v6
.line 90
new-instance v1, Ljava/io/File;
new-array v7, v2, [Ljava/lang/Object;
aput-object p2, v7, v4
invoke-static {v3}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;
move-result-object v8
aput-object v8, v7, v6
invoke-static {v5, v7}, Ljava/lang/String;->format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
move-result-object v7
invoke-direct {v1, v0, v7}, Ljava/io/File;-><init>(Ljava/io/File;Ljava/lang/String;)V
goto :goto_0
:cond_1
if-eqz v1, :cond_3
.line 94
invoke-virtual {v1}, Ljava/io/File;->length()J
move-result-wide v2
iget p2, p0, Lcom/orhanobut/logger/DiskLogStrategy$WriteHandler;->maxFileSize:I
int-to-long v4, p2
cmp-long p2, v2, v4
if-ltz p2, :cond_2
return-object p1
:cond_2
return-object v1
:cond_3
return-object p1
.end method
.method private writeLog(Ljava/io/FileWriter;Ljava/lang/String;)V
.locals 0
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/io/IOException;
}
.end annotation
.line 71
invoke-virtual {p1, p2}, Ljava/io/FileWriter;->append(Ljava/lang/CharSequence;)Ljava/io/Writer;
return-void
.end method
# virtual methods
.method public handleMessage(Landroid/os/Message;)V
.locals 4
.line 41
iget-object p1, p1, Landroid/os/Message;->obj:Ljava/lang/Object;
check-cast p1, Ljava/lang/String;
.line 44
iget-object v0, p0, Lcom/orhanobut/logger/DiskLogStrategy$WriteHandler;->folder:Ljava/lang/String;
const-string v1, "logs"
invoke-direct {p0, v0, v1}, Lcom/orhanobut/logger/DiskLogStrategy$WriteHandler;->getLogFile(Ljava/lang/String;Ljava/lang/String;)Ljava/io/File;
move-result-object v0
const/4 v1, 0x0
.line 47
:try_start_0
new-instance v2, Ljava/io/FileWriter;
const/4 v3, 0x1
invoke-direct {v2, v0, v3}, Ljava/io/FileWriter;-><init>(Ljava/io/File;Z)V
:try_end_0
.catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0
.line 49
:try_start_1
invoke-direct {p0, v2, p1}, Lcom/orhanobut/logger/DiskLogStrategy$WriteHandler;->writeLog(Ljava/io/FileWriter;Ljava/lang/String;)V
.line 51
invoke-virtual {v2}, Ljava/io/FileWriter;->flush()V
.line 52
invoke-virtual {v2}, Ljava/io/FileWriter;->close()V
:try_end_1
.catch Ljava/io/IOException; {:try_start_1 .. :try_end_1} :catch_1
goto :goto_0
:catch_0
move-object v2, v1
:catch_1
if-eqz v2, :cond_0
.line 56
:try_start_2
invoke-virtual {v2}, Ljava/io/FileWriter;->flush()V
.line 57
invoke-virtual {v2}, Ljava/io/FileWriter;->close()V
:try_end_2
.catch Ljava/io/IOException; {:try_start_2 .. :try_end_2} :catch_2
:catch_2
:cond_0
:goto_0
return-void
.end method