提交 69a765d3 编写于 作者: C caoyixiong 提交者: 彭勇升 pengys

FileUtils Transaction problem (#1996)

* close inputStream safety

* FIX NPE in AlarmService

* fix 5.x too many open files bug

* checkstyle bug

* checkstyle bug

* checkstyle bug

* fix offset bug

* change param name
上级 93aeb497
...@@ -43,8 +43,9 @@ public enum FileUtils { ...@@ -43,8 +43,9 @@ public enum FileUtils {
long position = length - 1; long position = length - 1;
randomAccessFile.seek(position); randomAccessFile.seek(position);
while (position >= 0) { while (position >= 0) {
if (randomAccessFile.read() == '\n') { String lineString = "";
return randomAccessFile.readLine(); if (randomAccessFile.read() == '\n' && StringUtils.isNotEmpty(lineString = randomAccessFile.readLine())) {
return lineString;
} }
randomAccessFile.seek(position); randomAccessFile.seek(position);
if (position == 0) { if (position == 0) {
...@@ -73,8 +74,7 @@ public enum FileUtils { ...@@ -73,8 +74,7 @@ public enum FileUtils {
randomAccessFile = new RandomAccessFile(file, "rwd"); randomAccessFile = new RandomAccessFile(file, "rwd");
long length = randomAccessFile.length(); long length = randomAccessFile.length();
randomAccessFile.seek(length); randomAccessFile.seek(length);
randomAccessFile.writeBytes(System.lineSeparator()); randomAccessFile.writeBytes(System.lineSeparator() + value);
randomAccessFile.writeBytes(value);
} catch (IOException e) { } catch (IOException e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
} finally { } finally {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册