#include <iostream>
#include "hdfs.h"

int main(int argc, char** argv) {
    hdfsFS fs = hdfsConnect("default", 0);

    if(!fs) {
        printf("error");
        exit(0);
    }

    hdfsFile wFile = hdfsOpenFile(fs, "test.hdfs", O_WRONLY, 8192, 0, 0);

    if(!wFile) {
        printf("error[2]");
        exit(0);
    }

    char* buf1 = (char*)malloc(sizeof(char) * 8192);
    strcpy(buf1, argv[1]);
    tSize size1 = 8192;
    size1 = hdfsWrite(fs, wFile, buf1, size1);
    free(buf1);
    hdfsCloseFile(fs, wFile);
    hdfsFile rFile = hdfsOpenFile(fs, "test.hdfs", O_RDONLY, 8192, 0, 0);

    if(!rFile) {
        printf("error");
        exit(0);
    }

    char* buf2 = (char*)malloc(sizeof(char) * 8192);
    tSize size2 = 8192;
    size2 = hdfsRead(fs, rFile, buf2, size2);

    printf("%s\r\n", buf2);

    free(buf2);
    hdfsCloseFile(fs, rFile);
    hdfsDisconnect(fs);

    return 0;
}

コンパイルは

g++ -Wall \
    -I/usr/lib/jvm/java-6-sun-1.6.0.22/include \
    -I/usr/lib/jvm/java-6-sun-1.6.0.22/include/linux \
    -L/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/client \
    -lhdfs \
    test.cc

又、実行時にはCLASSPAH環境変数にHadoopコアJARファイルとcommon-loggingが必要になる