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

net.fortytwo.flow.Buffer Maven / Gradle / Ivy

There is a newer version: 1.5
Show newest version
package net.fortytwo.flow;

import net.fortytwo.ripple.RippleException;

/**
 * A collection of data items which grows until "flushed" to a downstream sink.
 * @param  the type of data being passed
 *
 * @author Joshua Shinavier (http://fortytwo.net)
 */
public class Buffer extends Collector
{
	private final Sink sink;

    /**
     * Constructs a new buffer of the given type
     * @param sink the downstream sink to which to pass the received data items when the buffer is flushed
     */
	public Buffer( final Sink sink )
	{
		super();

		this.sink = sink;
	}

    /**
     * Empties the buffer, pushing the collected data items in FIFO order to the downstream sink
     * @throws RippleException
     */
	public void flush() throws RippleException
	{
		writeTo( sink );

		clear();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy