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

com.adgear.anoa.write.ThriftWriteConsumer Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 3.1.2
Show newest version
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);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy