com.adgear.anoa.write.WriteConsumer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of anoa-core Show documentation
Show all versions of anoa-core Show documentation
Core classes for Anoa library, which aims to be a safe, convenient and fast record
de/serialization wrapper for the Avro, Thrift and Jackson libraries, using the functional idioms
of Java 8.
The anoa-core module tries to keep upstream dependencies to a minimum.
package com.adgear.anoa.write;
import java.io.Closeable;
import java.io.Flushable;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.function.Consumer;
/**
* Implemented by consumers which perform write operations, and therefore may need to be flushed
* or closed.
*
* Methods in Anoa Utility classes matching #"\w+Consumer" usually return objects implementing this
* interface.
*
* @param Value type
* @see com.adgear.anoa.write.AvroConsumers
* @see com.adgear.anoa.write.JacksonConsumers
* @see com.adgear.anoa.write.ThriftConsumers
*/
public interface WriteConsumer extends Closeable, Flushable, Consumer {
/**
* Write the record somewhere
*
* @param record the record to be written
* @throws IOException raised when write fails
*/
void acceptChecked(T record) throws IOException;
/**
* Default implementation of {@link Consumer#accept} wraps {@link WriteConsumer#acceptChecked} by
* rethrowing any {@link IOException} as an {@link UncheckedIOException}
*
* @param record the record to be written
*/
default void accept(T record) {
try {
acceptChecked(record);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
/**
* Default implementation of {@link Closeable#close} calls {@link Flushable#flush}
*
* @throws IOException raised when close fails
*/
default void close() throws IOException {
flush();
}
}