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

org.unix4j.unix.tail.TailLinesFromEndProcessor Maven / Gradle / Ivy

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

import java.util.LinkedList;

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

class TailLinesFromEndProcessor extends AbstractTailProcessor {
	
	private final LinkedList tailLines = new LinkedList();

    @Override
    public void resetCountersAndFlush() {
        final LineProcessor output = getOutput();
        boolean more = true;
        while (!tailLines.isEmpty() && more) {
            more = output.processLine(tailLines.removeFirst());//remove to free memory
        }
        tailLines.clear();
    }

    public TailLinesFromEndProcessor(TailCommand command, ExecutionContext context, LineProcessor output) {
		super(command, context, output);
	}

	@Override
	public boolean processLine(Line line) {
		tailLines.add(line);
		if (tailLines.size() > count) {
			tailLines.removeFirst();
		}
		return true;//we want all lines
	}

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy