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

com.adgear.anoa.tools.runnable.AvroClearFields Maven / Gradle / Ivy

package com.adgear.anoa.tools.runnable;

import com.adgear.anoa.AnoaReflectionUtils;
import com.adgear.anoa.read.AvroStreams;
import com.adgear.anoa.tools.function.AnoaFieldNuller;
import com.adgear.anoa.write.AvroConsumers;
import com.adgear.anoa.write.WriteConsumer;

import org.apache.avro.specific.SpecificRecord;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UncheckedIOException;

public class AvroClearFields implements Runnable {

  final protected Class recordClass;
  final protected String[] fields;
  final protected InputStream inputStream;
  final protected OutputStream outputStream;

  public AvroClearFields(Class recordClass,
                         InputStream inputStream,
                         OutputStream outputStream,
                         String... fields) {
    this.recordClass = recordClass;
    this.fields = fields;
    this.inputStream = inputStream;
    this.outputStream = outputStream;
  }

  @Override
  public void run() {
    try (WriteConsumer consumer = AvroConsumers.batch(recordClass, outputStream)) {
      AvroStreams.batch(recordClass, inputStream)
          .map(new AnoaFieldNuller<>(fields))
          .forEach(consumer);
    } catch (IOException e) {
      throw new UncheckedIOException(e);
    }
  }

  static public void main(String[] args) throws Exception {
    new AvroClearFields<>(AnoaReflectionUtils.getAvroClass(System.getProperty("recordClass")),
                          System.in,
                          System.out,
                          System.getProperty("fields").split(","))
        .run();
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy