#include <iostream>

//
// Created by Frapo on 2018/2/9.
//
#include "hdfscore.cpp"

using namespace ::hdfs;
using ::asio::ip::tcp;

int main(int argc, char **argv) {

    static_cast<void>(argc);
    static_cast<void>(argv);

    std::cout << "Hello, World!" << std::endl;
    //int PORT = 9000;
    std::string host = "117.107.241.78";
    std::string fn = "/a.txt";

    // getting size of file.
    int file_size = 1000;

    void *buf = malloc(file_size);
    InputStream * isptr;

    try {
        isptr = open_hdfs_file("/a.txt", "127.0.0.1", 9000);
    }catch(std::bad_exception ef){
        printf("\n\ncannot open hdfs file, exception what() : %s ",ef.what());
        isptr = 0;
    }

    if(isptr == NULL){
        return -101;
    }

    read_a_file(isptr, buf, 100, 50);

}

/**
 *
 *     hdfsFS fs = hdfsConnect("default", 0);
    const char* writePath = "/tmp/testfile.txt";
    hdfsFile writeFile = hdfsOpenFile(fs, writePath, O_WRONLY|O_CREAT, 0, 0, 0);
    if(!writeFile) {
        fprintf(stderr, "Failed to open %s for writing!\n", writePath);
        exit(-1);
    }
    char* buffer = "Hello, World!";
    tSize num_written_bytes = hdfsWrite(fs, writeFile, (void*)buffer, strlen(buffer)+1);
    if (hdfsFlush(fs, writeFile)) {
        fprintf(stderr, "Failed to 'flush' %s\n", writePath);
        exit(-1);
    }
    hdfsCloseFile(fs, writeFile);* /


 * */