com.adgear.anoa.write.ThriftWriteConsumer 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 org.apache.thrift.TBase;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TTransport;
import java.io.IOException;
import java.util.function.Function;
class ThriftWriteConsumer implements WriteConsumer {
final TTransport tTransport;
final TProtocol tProtocol;
ThriftWriteConsumer(TTransport tTransport, Function protocolFactory) {
this.tTransport = tTransport;
this.tProtocol = protocolFactory.apply(tTransport);
}
@Override
public void flush() throws IOException {
try {
tTransport.flush();
} catch (TException e) {
throw new IOException(e);
}
}
@Override
public void close() throws IOException {
flush();
tTransport.close();
}
@Override
public void acceptChecked(T record) throws IOException {
try {
record.write(tProtocol);
} catch (TException e) {
throw new IOException(e);
}
}
}