File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed
src/main/java/org/audit4j/core/handler/file Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,9 @@ public final class ZeroCopyFileWriter extends AuditFileWriter implements Seriali
53
53
/** The path. */
54
54
private final String path ;
55
55
56
+ /** To track last opened random access file **/
57
+ String lastRealPath ;
58
+
56
59
/**
57
60
* Instantiates a new zero copy file writer.
58
61
*
@@ -89,11 +92,15 @@ public ZeroCopyFileWriter write(String event) {
89
92
FileHandlerUtil .generateAuditFileName ());
90
93
91
94
try {
92
- if (FileHandlerUtil .isFileAlreadyExists (realPath )) {
93
- randomAccessFile = new RandomAccessFile (realPath , CoreConstants .READ_WRITE );
94
- } else {
95
- randomAccessFile = new RandomAccessFile (new File (realPath ), CoreConstants .READ_WRITE );
96
- }
95
+ /** Close last instance for random access file. **/
96
+ if (randomAccessFile != null && !realPath .equals (lastRealPath )) {
97
+ this .stop ();
98
+ }
99
+
100
+ if (randomAccessFile == null ) {
101
+ lastRealPath = realPath ;
102
+ randomAccessFile = new RandomAccessFile (new File (realPath ), CoreConstants .READ_WRITE );
103
+ }
97
104
} catch (FileNotFoundException e ) {
98
105
// TODO Auto-generated catch block
99
106
e .printStackTrace ();
You can’t perform that action at this time.
0 commit comments