diff --git a/src/main/java/net/geedge/api/controller/APIController.java b/src/main/java/net/geedge/api/controller/APIController.java index 75e3bc0..8d04d32 100644 --- a/src/main/java/net/geedge/api/controller/APIController.java +++ b/src/main/java/net/geedge/api/controller/APIController.java @@ -317,7 +317,7 @@ public class APIController { throw new APIException(RCode.BAD_REQUEST); } Map result = Constant.PLAYBOOK_RUN_RESULT.get(id); - if (!T.MapUtil.getStr(result, "status").equals("running")){ + if (T.MapUtil.isNotEmpty(result) && !T.MapUtil.getStr(result, "status").equals("running")){ Constant.PLAYBOOK_RUN_RESULT.remove(id); } return R.ok().putData(result); @@ -333,14 +333,17 @@ public class APIController { // log file File logFile = T.FileUtil.file(Constant.TEMP_PATH, id, "result.log"); HashMap result = T.MapUtil.newHashMap(false); + try (RandomAccessFile raf = new RandomAccessFile(logFile, "r")) { - raf.seek(offset); - byte[] bytes = new byte[(int)raf.length() - offset]; - raf.readFully(bytes); - String content = new String(bytes); - result.put("content", content); - result.put("length", bytes.length); - result.put("offset", offset + bytes.length); + if (offset < raf.length()) { + raf.seek(offset); + byte[] bytes = new byte[(int)raf.length() - offset]; + raf.readFully(bytes); + String content = new String(bytes); + result.put("content", content); + result.put("length", bytes.length); + result.put("offset", offset + bytes.length); + } } catch (IOException e) { log.error("getJobResultLog error", e); throw new APIException(RCode.ERROR);