001package io.jstach.jstachio.output;
002
003import java.io.OutputStream;
004
005/**
006 * An OutputStream like callback.
007 *
008 * @param <E> exception that could be thrown while accepting byte data.
009 */
010@FunctionalInterface
011public interface OutputConsumer<E extends Exception> extends AutoCloseable {
012
013        /**
014         * Convenience method that will call the real accept.
015         * @param data array to be fully copied
016         * @throws E if consumer has an error
017         */
018        default void accept(byte[] data) throws E {
019                accept(data, 0, data.length);
020        }
021
022        /**
023         * Analagous to {@link OutputStream#write(byte[], int, int)}.
024         * @param data data
025         * @param offset offset
026         * @param length length
027         * @throws E if the consumer as an error
028         */
029        public void accept(byte[] data, int offset, int length) throws E;
030
031        @Override
032        default void close() throws E {
033        }
034
035}