package com.jasongj.spark.writer;

import com.jasongj.spark.model.TableMetaData;
import com.jasongj.spark.model.Tuple;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hive.metastore.api.TableMeta;

import java.io.DataOutputStream;

/**
 * Created by Jason Guo (jason.guo.vip@gmail.com)
 */
public abstract class TupleWriter {
    protected Path path;
    protected Configuration hadoopConfiguration;
    protected DataOutputStream dataOutputStream;
    protected TableMetaData outputTableMetaData;

    public TupleWriter(DataOutputStream dataOutputStream, Configuration hadoopConfiguration, Path path, TableMetaData outputTableMetaData) {
        this.dataOutputStream = dataOutputStream;
        this.hadoopConfiguration = hadoopConfiguration;
        this.path = path;
        this.outputTableMetaData = outputTableMetaData;
    }

    public boolean init() {
        return dataOutputStream != null && hadoopConfiguration != null && path != null && outputTableMetaData != null;
    }
    public abstract void write(Tuple tuple);
    public abstract void close();
}

@@ -112,16 +112,54 @@
 .Tuple;%0A
+import org.apache.commons.io.IOUtils;%0A
 import o
@@ -232,63 +232,8 @@
 ath;
-%0Aimport org.apache.hadoop.hive.metastore.api.TableMeta;
 %0A%0Aim
@@ -436,57 +436,8 @@
 on;%0A
-    protected DataOutputStream dataOutputStream;%0A
     
@@ -509,43 +509,8 @@
 ter(
-DataOutputStream dataOutputStream, 
 Conf
@@ -592,58 +592,8 @@
 ) %7B%0A
-        this.dataOutputStream = dataOutputStream;%0A
     
@@ -779,36 +779,8 @@
 turn
- dataOutputStream != null &&
  had

Refactor TupleWriter -- remove DataOutputStream from constructor and member variable