001package com.dpillay.tools.tail4j.core;
002
003import java.io.PrintStream;
004
005import com.dpillay.tools.tail4j.model.TailContents;
006
007public class PrintWriterTailPrinter<T> implements TailPrinter<T> {
008  private PrintStream printer = null;
009  private TailListener<T> listener = null;
010
011  public PrintWriterTailPrinter() {
012    super();
013  }
014
015  public PrintWriterTailPrinter(PrintStream printer, TailListener<T> listener) {
016    super();
017    this.printer = printer;
018    this.listener = listener;
019  }
020
021  public PrintStream getPrinter() {
022    return printer;
023  }
024
025  public void setPrinter(PrintStream printer) {
026    this.printer = printer;
027  }
028
029  public TailListener<T> getListener() {
030    return listener;
031  }
032
033  public void setListener(TailListener<T> listener) {
034    this.listener = listener;
035  }
036
037  @Override
038  public void print(TailContents<T> tailContents) {
039    printer.println(tailContents.getContents());
040  }
041
042  @Override
043  public T call() throws Exception {
044    TailContents<T> tailContents = null;
045    while ((tailContents = this.listener.poll()) != null) {
046      this.print(tailContents);
047    }
048    return null;
049  }
050}