Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.commons.io.input
Class Tailer

    java.lang.Object
      org.apache.commons.io.input.Tailer

All Implemented Interfaces:
  Runnable

    public class Tailer

extends Object
implements Runnable

Simple implementation of the unix "tail -f" functionality.

Example Usage:

          // Simplest invocation using static helper method:
          TailerListener listener = ...
          Tailer tailer = Tailer.create(file, listener, delay);

          // Alternative method using executor:
          TailerListener listener = ...
          Tailer tailer = new Tailer(file, listener, delay);
          Executor executor ...
          executor.execute(tailer);

          // Alternative method if you want to handle the threading yourself:
          TailerListener listener = ...
          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();

Since:
  Commons IO 2.0
Version:
  $Id: Tailer.java 1021884 2010-10-12 18:49:16Z ggregory $

Constructor Summary
`Tailer(File file, TailerListener listener)` Creates a Tailer for the given file, starting from the beginning, with the default delay of 1.0s.
`Tailer(File file, TailerListener listener, long delay)` Creates a Tailer for the given file, starting from the beginning.
`Tailer(File file, TailerListener listener, long delay, boolean end)` Creates a Tailer for the given file, with a delay other than the default 1.0s.

Method Summary
`static Tailer` | `create(File file, TailerListener listener)` Creates and starts a Tailer for the given file, starting at the beginning of the file with the default delay of 1.0s
`static Tailer` | `create(File file, TailerListener listener, long delay)` Creates and starts a Tailer for the given file, starting at the beginning of the file
`static Tailer` | `create(File file, TailerListener listener, long delay, boolean end)` Creates and starts a Tailer for the given file.
`long` | `getDelay()` Return the delay.
`File` | `getFile()` Return the file.
`void` | `run()` Follows changes in the file, calling the TailerListener's handle method for each new line.
`void` | `stop()` Allows the tailer to complete its current loop and return.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### Tailer

    public Tailer(File file,
                  TailerListener listener)

  Creates a Tailer for the given file, starting from the beginning, with the default delay of 1.0s.

  Parameters:
    `file` - The file to follow.
    `listener` - the TailerListener to use.

### Tailer

    public Tailer(File file,
                  TailerListener listener,
                  long delay)

  Creates a Tailer for the given file, starting from the beginning.

  Parameters:
    `file` - the file to follow.
    `listener` - the TailerListener to use.
    `delay` - the delay between checks of the file for new content in milliseconds.

### Tailer

    public Tailer(File file,
                  TailerListener listener,
                  long delay,
                  boolean end)

  Creates a Tailer for the given file, with a delay other than the default 1.0s.

  Parameters:
    `file` - the file to follow.
    `listener` - the TailerListener to use.
    `delay` - 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.

Method Detail

### create

    public static Tailer create(File file,
                                TailerListener listener,
                                long delay,
                                boolean end)

  Creates and starts a Tailer for the given file.

  Parameters:
    `file` - the file to follow.
    `listener` - the TailerListener to use.
    `delay` - 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.
  Returns:
    The new tailer

### create

    public static Tailer create(File file,
                                TailerListener listener,
                                long delay)

  Creates and starts a Tailer for the given file, starting at the beginning of the file

  Parameters:
    `file` - the file to follow.
    `listener` - the TailerListener to use.
    `delay` - the delay between checks of the file for new content in milliseconds.
  Returns:
    The new tailer

### create

    public static Tailer create(File file,
                                TailerListener listener)

  Creates and starts a Tailer for the given file, starting at the beginning of the file with the default delay of 1.0s

  Parameters:
    `file` - the file to follow.
    `listener` - the TailerListener to use.
  Returns:
    The new tailer

### getFile

    public File getFile()

  Return the file.

  Returns:
    the file

### getDelay

    public long getDelay()

  Return the delay.

  Returns:
    the delay

### run

    public void run()

  Follows changes in the file, calling the TailerListener's handle method for each new line.

  Specified by:
    `run` in interface `Runnable`

### stop

    public void stop()

  Allows the tailer to complete its current loop and return.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2002-2010 The Apache Software Foundation. All Rights Reserved.