fix: job 日志获取前校验 offset
This commit is contained in:
@@ -156,13 +156,20 @@ public class JobServiceImpl extends ServiceImpl<JobDao, JobEntity> implements IJ
|
|||||||
|
|
||||||
if (logFile.exists()){
|
if (logFile.exists()){
|
||||||
try (RandomAccessFile raf = new RandomAccessFile(logFile, "r")) {
|
try (RandomAccessFile raf = new RandomAccessFile(logFile, "r")) {
|
||||||
raf.seek(offset);
|
if (offset > raf.length()){
|
||||||
byte[] bytes = new byte[(int)raf.length() - offset];
|
result.put("content", T.StrUtil.EMPTY);
|
||||||
raf.readFully(bytes);
|
result.put("length", 0);
|
||||||
String content = new String(bytes);
|
result.put("offset", offset);
|
||||||
result.put("content", content);
|
}else {
|
||||||
result.put("length", bytes.length);
|
raf.seek(offset);
|
||||||
result.put("offset", offset + bytes.length);
|
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) {
|
} catch (IOException e) {
|
||||||
log.error("queryJobLog error", e);
|
log.error("queryJobLog error", e);
|
||||||
throw new ASWException(RCode.ERROR);
|
throw new ASWException(RCode.ERROR);
|
||||||
|
|||||||
Reference in New Issue
Block a user