Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
huangzhicong
/
SmartCanteen
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6a6efc75
authored
Jun 09, 2020
by
pye52
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化安装指令的业务逻辑
parent
1bc68326
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
16 deletions
+10
-16
app/src/main/java/com/bgycc/smartcanteen/command/UpdateCommandWorker.java
+10
-16
No files found.
app/src/main/java/com/bgycc/smartcanteen/command/UpdateCommandWorker.java
View file @
6a6efc75
...
...
@@ -16,9 +16,7 @@ import com.blankj.utilcode.util.LogUtils;
import
com.blankj.utilcode.util.PathUtils
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
okhttp3.OkHttpClient
;
import
okhttp3.Request
;
...
...
@@ -80,8 +78,8 @@ public class UpdateCommandWorker extends CommandWorker {
.
sslSocketFactory
(
TrustAllCerts
.
createSSLSocketFactory
(),
new
TrustAllCerts
())
.
build
();
InputStream
is
=
null
;
FileOutputStream
fos
=
null
;
BufferedSource
source
=
null
;
BufferedSink
sink
=
null
;
try
{
Response
response
=
client
.
newCall
(
request
).
execute
();
ResponseBody
body
=
response
.
body
();
...
...
@@ -90,14 +88,11 @@ public class UpdateCommandWorker extends CommandWorker {
return
failed
(
"更新包异常"
);
}
is
=
body
.
byteStream
();
fos
=
new
FileOutputStream
(
updateApk
);
long
total
=
body
.
contentLength
();
float
totalBytesRead
=
0
f
;
BufferedSource
source
=
body
.
source
();
BufferedSink
sink
=
Okio
.
buffer
(
Okio
.
sink
(
updateApk
));
source
=
body
.
source
();
sink
=
Okio
.
buffer
(
Okio
.
sink
(
updateApk
));
Buffer
sinkBuffer
=
sink
.
getBuffer
();
for
(
long
bytesRead
;
(
bytesRead
=
source
.
read
(
sinkBuffer
,
BUFFER_SIZE
))
!=
-
1
;
)
{
...
...
@@ -107,23 +102,22 @@ public class UpdateCommandWorker extends CommandWorker {
inProgress
(
"下载进度: "
+
progress
+
"%"
);
}
sink
.
flush
();
sink
.
close
();
source
.
close
();
body
.
close
();
response
.
close
();
}
catch
(
IOException
e
)
{
updateApk
.
deleteOnExit
(
);
FileUtils
.
delete
(
updateApk
);
LogUtils
.
w
(
TAG
,
"更新包下载失败: "
+
e
.
getMessage
(),
e
);
return
failed
(
"更新包下载失败"
);
}
finally
{
if
(
is
!=
null
)
{
if
(
sink
!=
null
)
{
try
{
is
.
close
();
sink
.
close
();
}
catch
(
IOException
ignored
)
{
}
}
if
(
fos
!=
null
)
{
if
(
source
!=
null
)
{
try
{
fos
.
close
();
source
.
close
();
}
catch
(
IOException
ignored
)
{
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment