001package org.unix4j.unix.head;
002
003import org.unix4j.context.ExecutionContext;
004import org.unix4j.processor.AbstractLineProcessor;
005import org.unix4j.processor.LineProcessor;
006import org.unix4j.util.Counter;
007
008/**
009 * Base class for the line processors used by the {@link HeadCommand}.
010 */
011abstract class AbstractHeadProcessor extends AbstractLineProcessor<HeadArguments> {
012        protected final long count;
013        protected final Counter counter = new Counter();
014
015        public AbstractHeadProcessor(HeadCommand command, ExecutionContext context, LineProcessor output) {
016                super(command, context, output);
017                final HeadArguments args = getArguments();
018                this.count = args.isCountSet() ? args.getCount() : 10;
019        }
020
021        @Override
022        public void finish() {
023                counter.reset();
024                getOutput().finish();
025        }
026
027    public void resetCounter(){
028        counter.reset();
029    }
030}