package com.tecspy.protocol;

import java.io.IOException;

/**
 * A processor of bytes from an input stream or similar.
 *
 * Decouples the reader of a stream from the processor of the bytes received from
 * that stream. Allows the creation of pluggable test/production interfaces.
 *
 * @author Michael Erskine
 *
 */
public interface ByteSink {
    /**
    * An input stream or similar has provided us with some bytes to process.
    *
    * @param buf
    *            array of buffered bytes
    * @param len
    *            number of relevant bytes from the buffer
    * @return some indication of activity, e.g. the number of bytes processed
    */
    public int processBytes(byte[] buf, int len);

    /**
    * An input stream or similar has encountered the end-of-file condition.
    */
    public void processEof();

    /**
    * An input stream or similar has encountered an exception during IO.
    *
    * @param e
    *            the exception encountered
    */
    public void processException(IOException e);
}