public class Tailer
extends java.lang.Object
implements java.lang.Runnable, java.lang.AutoCloseable
To build an instance, see Tailer.Builder.
First you need to create a TailerListener implementation; (TailerListenerAdapter is provided for
convenience so that you don't have to implement every method).
For example:
public class MyTailerListener extends TailerListenerAdapter {
public void handle(String line) {
System.out.println(line);
}
}
You can create and use a Tailer in one of three ways:
Tailer.BuilderExecutorThreadAn example of each is shown below.
TailerListener listener = new MyTailerListener(); Tailer tailer = Tailer.builder() .setFile(file) .setTailerListener(listener) .setDelayDuration(delay) .get();
TailerListener listener = new MyTailerListener();
Tailer tailer = new Tailer(file, listener, delay);
// stupid executor impl. for demo purposes
Executor executor = new Executor() {
public void execute(Runnable command) {
command.run();
}
};
executor.execute(tailer);
TailerListener listener = new MyTailerListener(); Tailer tailer = new Tailer(file, listener, delay); Thread thread = new Thread(tailer); thread.setDaemon(true); // optional thread.start();
Remember to stop the tailer when you have done with it:
tailer.stop();
You can interrupt the thread a tailer is running on by calling Thread.interrupt().
thread.interrupt();
If you interrupt a tailer, the tailer listener is called with the InterruptedException.
The file is read using the default Charset; this can be overridden if necessary.
Thread.interrupt()., 2.12.0 Add Tailer.Tailable and Tailer.RandomAccessResourceBridge interfaces to tail of files accessed using
alternative libraries such as jCIFS or Apache Commons
VFS.TailerListener,
TailerListenerAdapter| Modifier and Type | Class and Description |
|---|---|
static class |
Tailer.Builder
Builds a
Tailer with default values. |
static interface |
Tailer.RandomAccessResourceBridge
Bridges access to a resource for random access, normally a file.
|
static interface |
Tailer.Tailable
A tailable resource like a file.
|
| Constructor and Description |
|---|
Tailer(java.io.File file,
java.nio.charset.Charset charset,
TailerListener listener,
long delayMillis,
boolean end,
boolean reOpen,
int bufSize)
Deprecated.
Use
builder(), Tailer.Builder, and Tailer.Builder.get(). |
Tailer(java.io.File file,
TailerListener listener)
Deprecated.
Use
builder(), Tailer.Builder, and Tailer.Builder.get(). |
Tailer(java.io.File file,
TailerListener listener,
long delayMillis)
Deprecated.
Use
builder(), Tailer.Builder, and Tailer.Builder.get(). |
Tailer(java.io.File file,
TailerListener listener,
long delayMillis,
boolean end)
Deprecated.
Use
builder(), Tailer.Builder, and Tailer.Builder.get(). |
Tailer(java.io.File file,
TailerListener listener,
long delayMillis,
boolean end,
boolean reOpen)
Deprecated.
Use
builder(), Tailer.Builder, and Tailer.Builder.get(). |
Tailer(java.io.File file,
TailerListener listener,
long delayMillis,
boolean end,
boolean reOpen,
int bufferSize)
Deprecated.
Use
builder(), Tailer.Builder, and Tailer.Builder.get(). |
Tailer(java.io.File file,
TailerListener listener,
long delayMillis,
boolean end,
int bufferSize)
Deprecated.
Use
builder(), Tailer.Builder, and Tailer.Builder.get(). |
| Modifier and Type | Method and Description |
|---|---|
static Tailer.Builder |
builder()
Constructs a new
Tailer.Builder. |
void |
close()
Requests the tailer to complete its current loop and return.
|
static Tailer |
create(java.io.File file,
java.nio.charset.Charset charset,
TailerListener listener,
long delayMillis,
boolean end,
boolean reOpen,
int bufferSize)
Deprecated.
Use
builder(), Tailer.Builder, and Tailer.Builder.get(). |
static Tailer |
create(java.io.File file,
TailerListener listener)
Deprecated.
Use
builder(), Tailer.Builder, and Tailer.Builder.get(). |
static Tailer |
create(java.io.File file,
TailerListener listener,
long delayMillis)
Deprecated.
Use
builder(), Tailer.Builder, and Tailer.Builder.get(). |
static Tailer |
create(java.io.File file,
TailerListener listener,
long delayMillis,
boolean end)
Deprecated.
Use
builder(), Tailer.Builder, and Tailer.Builder.get(). |
static Tailer |
create(java.io.File file,
TailerListener listener,
long delayMillis,
boolean end,
boolean reOpen)
Deprecated.
Use
builder(), Tailer.Builder, and Tailer.Builder.get(). |
static Tailer |
create(java.io.File file,
TailerListener listener,
long delayMillis,
boolean end,
boolean reOpen,
int bufferSize)
Deprecated.
Use
builder(), Tailer.Builder, and Tailer.Builder.get(). |
static Tailer |
create(java.io.File file,
TailerListener listener,
long delayMillis,
boolean end,
int bufferSize)
Deprecated.
Use
builder(), Tailer.Builder, and Tailer.Builder.get(). |
long |
getDelay()
Deprecated.
Use
getDelayDuration(). |
java.time.Duration |
getDelayDuration()
Gets the delay Duration.
|
java.io.File |
getFile()
Gets the file.
|
Tailer.Tailable |
getTailable()
Gets the Tailable.
|
void |
run()
Follows changes in the file, calling
TailerListener.handle(String) with each new line. |
void |
stop()
Deprecated.
Use
close(). |
@Deprecated
public Tailer(java.io.File file,
java.nio.charset.Charset charset,
TailerListener listener,
long delayMillis,
boolean end,
boolean reOpen,
int bufSize)
builder(), Tailer.Builder, and Tailer.Builder.get().file - the file to follow.charset - the Charset to be used for reading the filelistener - the TailerListener to use.delayMillis - the delay between checks of the file for new content in milliseconds.end - Set to true to tail from the end of the file, false to tail from the beginning of the file.reOpen - if true, close and reopen the file between reading chunksbufSize - Buffer size@Deprecated
public Tailer(java.io.File file,
TailerListener listener)
builder(), Tailer.Builder, and Tailer.Builder.get().file - The file to follow.listener - the TailerListener to use.@Deprecated
public Tailer(java.io.File file,
TailerListener listener,
long delayMillis)
builder(), Tailer.Builder, and Tailer.Builder.get().file - the file to follow.listener - the TailerListener to use.delayMillis - the delay between checks of the file for new content in milliseconds.@Deprecated
public Tailer(java.io.File file,
TailerListener listener,
long delayMillis,
boolean end)
builder(), Tailer.Builder, and Tailer.Builder.get().file - the file to follow.listener - the TailerListener to use.delayMillis - the delay between checks of the file for new content in milliseconds.end - Set to true to tail from the end of the file, false to tail from the beginning of the file.@Deprecated
public Tailer(java.io.File file,
TailerListener listener,
long delayMillis,
boolean end,
boolean reOpen)
builder(), Tailer.Builder, and Tailer.Builder.get().file - the file to follow.listener - the TailerListener to use.delayMillis - the delay between checks of the file for new content in milliseconds.end - Set to true to tail from the end of the file, false to tail from the beginning of the file.reOpen - if true, close and reopen the file between reading chunks@Deprecated
public Tailer(java.io.File file,
TailerListener listener,
long delayMillis,
boolean end,
boolean reOpen,
int bufferSize)
builder(), Tailer.Builder, and Tailer.Builder.get().file - the file to follow.listener - the TailerListener to use.delayMillis - the delay between checks of the file for new content in milliseconds.end - Set to true to tail from the end of the file, false to tail from the beginning of the file.reOpen - if true, close and reopen the file between reading chunksbufferSize - Buffer size@Deprecated
public Tailer(java.io.File file,
TailerListener listener,
long delayMillis,
boolean end,
int bufferSize)
builder(), Tailer.Builder, and Tailer.Builder.get().file - the file to follow.listener - the TailerListener to use.delayMillis - the delay between checks of the file for new content in milliseconds.end - Set to true to tail from the end of the file, false to tail from the beginning of the file.bufferSize - Buffer sizepublic static Tailer.Builder builder()
Tailer.Builder.Tailer.Builder.@Deprecated public static Tailer create(java.io.File file, java.nio.charset.Charset charset, TailerListener listener, long delayMillis, boolean end, boolean reOpen, int bufferSize)
builder(), Tailer.Builder, and Tailer.Builder.get().file - the file to follow.charset - the character set to use for reading the file.listener - the TailerListener to use.delayMillis - the delay between checks of the file for new content in milliseconds.end - Set to true to tail from the end of the file, false to tail from the beginning of the file.reOpen - whether to close/reopen the file between chunks.bufferSize - buffer size.@Deprecated public static Tailer create(java.io.File file, TailerListener listener)
builder(), Tailer.Builder, and Tailer.Builder.get().file - the file to follow.listener - the TailerListener to use.@Deprecated public static Tailer create(java.io.File file, TailerListener listener, long delayMillis)
builder(), Tailer.Builder, and Tailer.Builder.get().file - the file to follow.listener - the TailerListener to use.delayMillis - the delay between checks of the file for new content in milliseconds.@Deprecated public static Tailer create(java.io.File file, TailerListener listener, long delayMillis, boolean end)
builder(), Tailer.Builder, and Tailer.Builder.get().file - the file to follow.listener - the TailerListener to use.delayMillis - the delay between checks of the file for new content in milliseconds.end - Set to true to tail from the end of the file, false to tail from the beginning of the file.@Deprecated public static Tailer create(java.io.File file, TailerListener listener, long delayMillis, boolean end, boolean reOpen)
builder(), Tailer.Builder, and Tailer.Builder.get().file - the file to follow.listener - the TailerListener to use.delayMillis - the delay between checks of the file for new content in milliseconds.end - Set to true to tail from the end of the file, false to tail from the beginning of the file.reOpen - whether to close/reopen the file between chunks.@Deprecated public static Tailer create(java.io.File file, TailerListener listener, long delayMillis, boolean end, boolean reOpen, int bufferSize)
builder(), Tailer.Builder, and Tailer.Builder.get().file - the file to follow.listener - the TailerListener to use.delayMillis - the delay between checks of the file for new content in milliseconds.end - Set to true to tail from the end of the file, false to tail from the beginning of the file.reOpen - whether to close/reopen the file between chunks.bufferSize - buffer size.@Deprecated public static Tailer create(java.io.File file, TailerListener listener, long delayMillis, boolean end, int bufferSize)
builder(), Tailer.Builder, and Tailer.Builder.get().file - the file to follow.listener - the TailerListener to use.delayMillis - the delay between checks of the file for new content in milliseconds.end - Set to true to tail from the end of the file, false to tail from the beginning of the file.bufferSize - buffer size.public void close()
close in interface java.lang.AutoCloseable@Deprecated public long getDelay()
getDelayDuration().public java.time.Duration getDelayDuration()
public java.io.File getFile()
java.lang.IllegalStateException - if constructed using a user provided Tailer.Tailable implementationpublic Tailer.Tailable getTailable()
public void run()
TailerListener.handle(String) with each new line.run in interface java.lang.Runnable@Deprecated public void stop()
close().Copyright © 2010 - 2023 Adobe. All Rights Reserved