Skip to content

Commit 69e3b81

Browse files
author
Gary Gregory
committed
Method that allocates should release resources.
Use try-with-resources with Tailer as an AutoCloseable. All tests now manage its own resource.
1 parent d6d99a6 commit 69e3b81

2 files changed

Lines changed: 247 additions & 226 deletions

File tree

src/main/java/org/apache/commons/io/input/Tailer.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
* alternative libraries such as jCIFS or <a href="https://commons.apache.org/proper/commons-vfs/">Apache Commons
156156
* VFS</a>.
157157
*/
158-
public class Tailer implements Runnable {
158+
public class Tailer implements Runnable, AutoCloseable {
159159

160160
/**
161161
* Builds a {@link Tailer} with default values.
@@ -768,6 +768,14 @@ private Tailer(final Tailable tailable, final Charset charset, final TailerListe
768768
this.charset = charset;
769769
}
770770

771+
/**
772+
* Requests the tailer to complete its current loop and return.
773+
*/
774+
@Override
775+
public void close() {
776+
this.run = false;
777+
}
778+
771779
/**
772780
* Gets the delay in milliseconds.
773781
*
@@ -963,14 +971,17 @@ public void run() {
963971
} catch (final IOException e) {
964972
listener.handle(e);
965973
}
966-
stop();
974+
close();
967975
}
968976
}
969977

970978
/**
971979
* Requests the tailer to complete its current loop and return.
980+
*
981+
* @deprecated Use {@link #close()}.
972982
*/
983+
@Deprecated
973984
public void stop() {
974-
this.run = false;
985+
close();
975986
}
976987
}

0 commit comments

Comments
 (0)