@@ -63,21 +63,6 @@ public class Tailer implements Runnable {
6363 */
6464 private volatile boolean run = true ;
6565
66- /**
67- * The object which will be responsible for actually reading the file.
68- */
69- private RandomAccessFile reader ;
70-
71- /**
72- * The last position in the file that was read.
73- */
74- private long position ;
75-
76- /**
77- * The last time the file was checked for changes.
78- */
79- private long last ;
80-
8166 /**
8267 * Creates SimpleTailer for the given file.
8368 * @param file The file to follow.
@@ -138,6 +123,9 @@ public long getDelay() {
138123 */
139124 public void run () {
140125 try {
126+ long last = 0 ; // The last time the file was checked for changes
127+ long position = 0 ; // position within the file
128+ RandomAccessFile reader = null ;
141129 // Open the file
142130 while (run && reader == null ) {
143131 try {
@@ -183,7 +171,8 @@ public void run() {
183171 if (length > position ) {
184172
185173 // The file has more content than it did last time
186- readLines ();
174+ last = System .currentTimeMillis ();
175+ position = readLines (reader );
187176
188177 } else if (FileUtils .isFileNewer (file , last )) {
189178
@@ -195,7 +184,8 @@ public void run() {
195184 reader .seek (position );
196185
197186 // Now we can read new lines
198- readLines ();
187+ last = System .currentTimeMillis ();
188+ position = readLines (reader );
199189 }
200190 }
201191
@@ -220,14 +210,13 @@ public void stop() {
220210 * Read new lines.
221211 * @throws java.io.IOException if an I/O error occurs.
222212 */
223- private void readLines () throws IOException {
224- last = System .currentTimeMillis ();
213+ private long readLines (RandomAccessFile reader ) throws IOException {
225214 String line = reader .readLine ();
226215 while (line != null ) {
227216 listener .handle (line );
228217 line = reader .readLine ();
229218 }
230- position = reader .getFilePointer ();
219+ return reader .getFilePointer ();
231220 }
232221
233222}
0 commit comments