Created
September 11, 2017 23:17
-
-
Save Tagar/7c42f82f5538004bda2f4ea0b0e0adc5 to your computer and use it in GitHub Desktop.
hdfs_write_example.c using JNI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include "hdfs.h" | |
void logging (const char *msg) | |
{ | |
fprintf(stderr, "%s\n", msg); | |
} | |
int main(int argc, char **argv) { | |
logging("hdfsConnect().."); | |
hdfsFS fs = hdfsConnect("pc1udatahad121", 8020); | |
logging("hdfsConnect()ed"); | |
const char* writePath = "/tmp/testfile.txt"; | |
hdfsFile writeFile = hdfsOpenFile(fs, writePath, O_WRONLY |O_CREAT, 0, 0, 0); | |
logging("HDFS file opened for writing"); | |
if(!writeFile) { | |
fprintf(stderr, "Failed to open %s for writing!\n", writePath); | |
exit(10); | |
} | |
char* buffer = "Hello, World!"; | |
tSize num_written_bytes = hdfsWrite(fs, writeFile, (void*)buffer, strlen(buffer)+1); | |
logging("hdfsWrite() complete; not flushed yet"); | |
if (hdfsFlush(fs, writeFile)) { | |
fprintf(stderr, "Failed to 'flush' %s\n", writePath); | |
exit(10); | |
} | |
logging("about to close the file"); | |
hdfsCloseFile(fs, writeFile); | |
logging("hdfsCloseFile() complete"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment