001package org.unix4j.unix.wc; 002 003import org.unix4j.context.ExecutionContext; 004import org.unix4j.line.Line; 005import org.unix4j.processor.AbstractLineProcessor; 006import org.unix4j.processor.LineProcessor; 007 008/** 009 * Standard input processor for line, word and char count. 010 */ 011final class WcProcessor extends AbstractLineProcessor<WcArguments> { 012 private final Counters counters; 013 014 public WcProcessor(WcCommand command, ExecutionContext context, LineProcessor output) { 015 super(command, context, output); 016 counters = new Counters(getArguments()); 017 } 018 019 @Override 020 public boolean processLine(Line line) { 021 counters.update(line); 022 return true;//we want to count all lines 023 } 024 025 @Override 026 public void finish() { 027 final LineProcessor output = getOutput(); 028 counters.writeCountsLine(output); 029 output.finish(); 030 } 031}