All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.unix4j.unix.wc.WcProcessor Maven / Gradle / Ivy

There is a newer version: 0.6
Show newest version
package org.unix4j.unix.wc;

import org.unix4j.context.ExecutionContext;
import org.unix4j.line.Line;
import org.unix4j.processor.AbstractLineProcessor;
import org.unix4j.processor.LineProcessor;

/**
 * Standard input processor for line, word and char count.
 */
final class WcProcessor extends AbstractLineProcessor {
	private final Counters counters;

	public WcProcessor(WcCommand command, ExecutionContext context, LineProcessor output) {
		super(command, context, output);
		counters = new Counters(getArguments());
	}

	@Override
	public boolean processLine(Line line) {
		counters.update(line);
		return true;//we want to count all lines
	}

	@Override
	public void finish() {
		final LineProcessor output = getOutput();
		counters.writeCountsLine(output);
		output.finish();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy