fix line bug

This commit is contained in:
looly
2021-12-12 09:58:43 +08:00
parent 480b99a727
commit a9bd7c3bb4
3 changed files with 7 additions and 6 deletions

View File

@@ -3,10 +3,11 @@
-------------------------------------------------------------------------------------------------------------
# 5.7.18 (2021-12-09)
# 5.7.18 (2021-12-12)
### 🐣新特性
### 🐞Bug修复
* 【core 】 LineReadWatcher#onModify文件清空判断问题issue#2013@Github
-------------------------------------------------------------------------------------------------------------
# 5.7.17 (2021-12-09)

View File

@@ -50,11 +50,11 @@ public class LineReadWatcher extends SimpleWatcher implements Runnable {
try {
final long currentLength = randomAccessFile.length();
final long position = randomAccessFile.getFilePointer();
if (0 == currentLength || position == currentLength) {
if (position == currentLength) {
// 内容长度不变时忽略此次事件
return;
} else if (currentLength < position) {
// 如果内容变短,说明文件做了删改,回到内容末尾
// 如果内容变短或变0,说明文件做了删改或清空,回到内容末尾或0
randomAccessFile.seek(currentLength);
return;
}

View File

@@ -7,13 +7,13 @@ import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.CharsetUtil;
public class TailerTest {
@Test
@Ignore
public void tailTest() {
FileUtil.tail(FileUtil.file("e:/tail.txt"), CharsetUtil.CHARSET_GBK);
FileUtil.tail(FileUtil.file("d:/test/tail.txt"), CharsetUtil.CHARSET_GBK);
}
@Test
@Ignore
public void tailWithLinesTest() {