<commit_before>/*
 *
 *   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 <NAME>(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<commit_msg>add transformer for different File Types<commit_after>/*
 *
 *   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 <NAME>(https://github.com/boliza)
 */
public abstract class FileReader implements Reader {

    private AsyncFile file;
    private transient JsonObject currentRow;

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

    public abstract RecordParser parser();

    public abstract Function<Buffer, JsonObject> transformer();

    @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 = transformer().apply(event);
            handler.handle(currentRow);
        });
        return this;
    }

    @Override
{'fraction_non_alphanumeric': 0.09360780065005417, 'fraction_numerical': 0.005200433369447454, 'mean_word_length': 2.7681632653061223, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4895615', 'n_tokens_mistral': 1294, 'n_tokens_neox': 1255, 'n_words': 358}