You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Sébastien Roux <ro...@gmail.com> on 2010/11/10 13:24:20 UTC

[IO] tailer sample code

I'm not a Java specialist but quite curious about the new tailer classes in
commons IO 2.0.

Now what does this mean : TailerListener listener = ...

I mean what I am supposed to put after the equal? Would you have a quick
example regarding basic file tailing implementation?

I also checked this without getting the picture =>
http://permalink.gmane.org/gmane.comp.jakarta.commons.scm/9636

Many thanks for any guidance you may provide.

Sébastien Roux
mail:  roux.sebastien@gmail.com

Re: [IO] tailer sample code

Posted by Niall Pemberton <ni...@gmail.com>.
2010/11/10 Sébastien Roux <ro...@gmail.com>:
> I'm not a Java specialist but quite curious about the new tailer classes in
> commons IO 2.0.
>
> Now what does this mean : TailerListener listener = ...

Its just an abbreviation to show the line is not complete.

You have to create your own TailerListener implementation which does
whatever you want with the lines added to the file. So for example you
could do something like the following:

    /**
     * TailerListener implementation.
     */
    public class ShowLinesListener extends TailerListenerAdapter {
        @Override
        public void handle(String line) {
            System.out.println(line);
        }
    }

Then create the Tailer with your implementation:

    TailerListener listener = new ShowLinesListener();
    Tailer tailer = Tailer.create(file, listener, delay);

http://commons.apache.org/io/api-release/org/apache/commons/io/input/Tailer.html

Niall

> I mean what I am supposed to put after the equal? Would you have a quick
> example regarding basic file tailing implementation?
>
> I also checked this without getting the picture =>
> http://permalink.gmane.org/gmane.comp.jakarta.commons.scm/9636
>
> Many thanks for any guidance you may provide.
>
> Sébastien Roux
> mail:  roux.sebastien@gmail.com
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org