重构为Java7语法
This commit is contained in:
parent
093772c824
commit
51a1cf1e26
@ -48,24 +48,29 @@ public class TomCat {
|
|||||||
.url(zipUrl)
|
.url(zipUrl)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = client.newCall(request).execute()) {
|
try {
|
||||||
|
Response response = client.newCall(request).execute();
|
||||||
if (!response.isSuccessful()) {
|
if (!response.isSuccessful()) {
|
||||||
throw new IOException("Unexpected code " + response);
|
throw new IOException("Unexpected code " + response);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 下载 ZIP 文件到临时位置
|
// 下载 ZIP 文件到临时位置
|
||||||
File tempZipFile = File.createTempFile("temp", ".zip");
|
File tempZipFile = File.createTempFile("temp", ".zip");
|
||||||
try (InputStream inputStream = response.body().byteStream();
|
try {
|
||||||
FileOutputStream outputStream = new FileOutputStream(tempZipFile)) {
|
InputStream inputStream = response.body().byteStream();
|
||||||
|
FileOutputStream outputStream = new FileOutputStream(tempZipFile);
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[1024];
|
||||||
int length;
|
int length;
|
||||||
while ((length = inputStream.read(buffer)) > 0) {
|
while ((length = inputStream.read(buffer)) > 0) {
|
||||||
outputStream.write(buffer, 0, length);
|
outputStream.write(buffer, 0, length);
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解压 ZIP 文件到指定文件夹
|
// 解压 ZIP 文件到指定文件夹
|
||||||
try (ZipInputStream zipInputStream = new ZipInputStream(Files.newInputStream(tempZipFile.toPath()))) {
|
try {
|
||||||
|
ZipInputStream zipInputStream = new ZipInputStream(Files.newInputStream(tempZipFile.toPath()));
|
||||||
ZipEntry zipEntry;
|
ZipEntry zipEntry;
|
||||||
while ((zipEntry = zipInputStream.getNextEntry()) != null) {
|
while ((zipEntry = zipInputStream.getNextEntry()) != null) {
|
||||||
Path targetFilePath = Paths.get(destinationFolder, zipEntry.getName());
|
Path targetFilePath = Paths.get(destinationFolder, zipEntry.getName());
|
||||||
@ -83,11 +88,15 @@ public class TomCat {
|
|||||||
}
|
}
|
||||||
zipInputStream.closeEntry();
|
zipInputStream.closeEntry();
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除临时 ZIP 文件
|
// 删除临时 ZIP 文件
|
||||||
tempZipFile.delete();
|
tempZipFile.delete();
|
||||||
LogUtils.d(TAG, "已更新 BoBullToon 数据");
|
LogUtils.d(TAG, "已更新 BoBullToon 数据");
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user