/*
 *
 *   Copyright (C) 2015-2017 Monogram Inc.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

package io.metagraph.etl.reader.impl;

import java.util.function.Function;

import io.metagraph.etl.reader.Reader;
import io.metagraph.etl.reader.config.ReaderConfig;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.file.AsyncFile;
import io.vertx.core.json.JsonObject;
import io.vertx.core.parsetools.RecordParser;
import io.vertx.core.streams.ReadStream;

/**
 * @author Ranger Tsao(https://github.com/boliza)
 */
public abstract class FileReader implements Reader {

    private AsyncFile file;
    private Function<Buffer, JsonObject> transform;//init by reader config
    private transient JsonObject currentRow;

    public FileReader(Vertx vertx, JsonObject config) {
        vertx.executeBlocking(h -> {
                              },
                              r -> {
                              });
    }

    public abstract RecordParser parser();

    @Override
    public ReaderConfig getReaderConfig() {
        return null;
    }

    @Override
    public JsonObject nextRow() {
        return currentRow;
    }

    @Override
    public void close(Handler<AsyncResult<Void>> completionHandler) {
        file.close(completionHandler);
    }

    @Override
    public ReadStream<JsonObject> exceptionHandler(Handler<Throwable> handler) {
        return null;
    }

    @Override
    public ReadStream<JsonObject> handler(Handler<JsonObject> handler) {
        file.handler(event -> {
            currentRow = transform.apply(event);
            handler.handle(currentRow);
        });
        return this;
    }

    @Override
    public ReadStream<JsonObject> pause() {
        file.pause();
        return this;
    }

    @Override
    public ReadStream<JsonObject> resume() {
        file.resume();
        return this;
    }

    @Override
    public ReadStream<JsonObject> endHandler(Handler<Void> endHandler) {
        file.endHandler(endHandler);
        return this;
    }
}

@@ -1221,83 +1221,8 @@
 le;%0A
-    private Function%3CBuffer, JsonObject%3E transform;//init by reader config%0A
     
@@ -1511,16 +1511,81 @@
 ser();%0A%0A
+    public abstract Function%3CBuffer, JsonObject%3E transformer();%0A%0A
     @Ove
@@ -2150,16 +2150,20 @@
 ransform
+er()
 .apply(e

add transformer for different File Types