From 4f2b9f97e09f1bdb0fe794b4a63a9bd345a8ed85 Mon Sep 17 00:00:00 2001 From: john180 Date: Sat, 19 Aug 2023 01:29:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3okhttp=E7=9A=84ResponseBody?= =?UTF-8?q?=E6=B2=A1=E6=9C=89close=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../maa/backend/service/ArkLevelService.java | 45 +++++++++---------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/src/main/java/plus/maa/backend/service/ArkLevelService.java b/src/main/java/plus/maa/backend/service/ArkLevelService.java index cd2f3876..6e70428f 100644 --- a/src/main/java/plus/maa/backend/service/ArkLevelService.java +++ b/src/main/java/plus/maa/backend/service/ArkLevelService.java @@ -173,32 +173,27 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { - if (!response.isSuccessful()) { - task.fail(); - log.error("[LEVEL]下载地图数据失败:" + tree.getPath()); - return; + try (ResponseBody rspBody = response.body()) { + if (!response.isSuccessful()) { + task.fail(); + log.error("[LEVEL]下载地图数据失败:" + tree.getPath()); + return; + } + ArkTilePos tilePos = mapper.readValue(rspBody.string(), ArkTilePos.class); + ArkLevel level = parserService.parseLevel(tilePos, tree.getSha()); + if (level == null) { + task.fail(); + log.info("[LEVEL]地图数据解析失败:" + tree.getPath()); + return; + } else if (level == ArkLevel.EMPTY) { + task.pass(); + return; + } + arkLevelRepo.save(level); + + task.success(); + log.info("[LEVEL]下载地图数据 {} 成功, 进度{}/{}, 用时:{}s", tilePos.getName(), task.getCurrent(), task.getTotal(), task.getDuration()); } - ResponseBody body = response.body(); - if (body == null) { - task.fail(); - log.error("[LEVEL]下载地图数据失败:" + tree.getPath()); - return; - } - ArkTilePos tilePos = mapper.readValue(body.string(), ArkTilePos.class); - - ArkLevel level = parserService.parseLevel(tilePos, tree.getSha()); - if (level == null) { - task.fail(); - log.info("[LEVEL]地图数据解析失败:" + tree.getPath()); - return; - } else if (level == ArkLevel.EMPTY) { - task.pass(); - return; - } - arkLevelRepo.save(level); - - task.success(); - log.info("[LEVEL]下载地图数据 {} 成功, 进度{}/{}, 用时:{}s", tilePos.getName(), task.getCurrent(), task.getTotal(), task.getDuration()); } }); }