001package org.unix4j.unix.tail;
002
003import org.unix4j.context.ExecutionContext;
004import org.unix4j.line.Line;
005import org.unix4j.processor.LineProcessor;
006import org.unix4j.util.Counter;
007
008class TailLinesFromStartProcessor extends AbstractTailProcessor {
009
010        private final Counter counter = new Counter();
011
012    @Override
013    public void resetCountersAndFlush() {
014        counter.reset();
015    }
016
017    public TailLinesFromStartProcessor(TailCommand command, ExecutionContext context, LineProcessor output) {
018                super(command, context, output);
019        }
020
021        @Override
022        public boolean processLine(Line line) {
023                if (counter.increment() >= count) {
024                        return getOutput().processLine(line);
025                } else {
026                        return true;//we want more lines
027                }
028        }
029
030        @Override
031        public void finish() {
032        resetCountersAndFlush();
033                getOutput().finish();
034        }
035
036}