Package VASSAL.tools.io
Class Tailer
java.lang.Object
VASSAL.tools.io.Tailer
public class Tailer extends Object
Tail a file. This class is designed to behave similarly to the UNIX
command
tail -f, watching the file for changes and
reporting them to listeners. The tailer may be stopped when it is not
needed; if it is restarted, it will remember its last position and
resume reading where it left off.- Since:
- 3.2.0
- Author:
- Joel Uckelman
-
Field Summary
Fields Modifier and Type Field Description protected static longDEFAULT_POLL_INTERVALprotected Filefileprotected EventListenerSupport<String>lsupprotected longpoll_intervalprotected longpositionprotected booleantailing -
Constructor Summary
-
Method Summary
Modifier and Type Method Description voidaddEventListener(EventListener<? super String> l)Adds anEventListener.List<EventListener<? super String>>getEventListeners()Gets the list of listerners.FilegetFile()Gets the file being tailed.booleanhasEventListeners()Checks whether there are anyEventListeners.booleanisTailing()Checks whether the tailer is running.static voidmain(String[] args)voidremoveEventListener(EventListener<? super String> l)Removes anEventListener.voidstart()Starts tailing the file.voidstop()Stops tailing the file.
-
Field Details
-
DEFAULT_POLL_INTERVAL
protected static final long DEFAULT_POLL_INTERVAL- See Also:
- Constant Field Values
-
file
-
poll_interval
protected final long poll_interval -
position
protected long position -
tailing
protected volatile boolean tailing -
lsup
-
-
Constructor Details
-
Tailer
Creates a file tailer with the default polling interval.- Parameters:
file- the file to tail
-
Tailer
Creates a file tailer.- Parameters:
file- the file to tailpoll_interval- the polling interval, in milliseconds
-
Tailer
Creates a file tailer.- Parameters:
file- the file to tailpoll_interval- the polling interval, in millisecondslsup- the listener support
-
-
Method Details
-
start
Starts tailing the file.- Throws:
IOException
-
stop
public void stop()Stops tailing the file. -
isTailing
public boolean isTailing()Checks whether the tailer is running.- Returns:
trueif the tailer is running
-
getFile
Gets the file being tailed.- Returns:
- the file
-
addEventListener
Adds anEventListener.- Parameters:
l- the listener to add
-
removeEventListener
Removes anEventListener.- Parameters:
l- the listener to remove
-
hasEventListeners
public boolean hasEventListeners()Checks whether there are anyEventListeners.- Returns:
trueif there are any listeners
-
getEventListeners
Gets the list of listerners.- Returns:
- the list of listeners
-
main
- Throws:
IOException
-