hdfsmain.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <iostream>
  2. //
  3. // Created by Frapo on 2018/2/9.
  4. //
  5. #include "hdfscore.cpp"
  6. using namespace ::hdfs;
  7. using ::asio::ip::tcp;
  8. int main(int argc, char **argv) {
  9. static_cast<void>(argc);
  10. static_cast<void>(argv);
  11. std::cout << "Hello, World!" << std::endl;
  12. //int PORT = 9000;
  13. std::string host = "117.107.241.78";
  14. std::string fn = "/a.txt";
  15. // getting size of file.
  16. int file_size = 1000;
  17. void *buf = malloc(file_size);
  18. InputStream * isptr;
  19. try {
  20. isptr = open_hdfs_file("/a.txt", "127.0.0.1", 9000);
  21. }catch(std::bad_exception ef){
  22. printf("\n\ncannot open hdfs file, exception what() : %s ",ef.what());
  23. isptr = 0;
  24. }
  25. if(isptr == NULL){
  26. return -101;
  27. }
  28. read_a_file(isptr, buf, 100, 50);
  29. }
  30. /**
  31. *
  32. * hdfsFS fs = hdfsConnect("default", 0);
  33. const char* writePath = "/tmp/testfile.txt";
  34. hdfsFile writeFile = hdfsOpenFile(fs, writePath, O_WRONLY|O_CREAT, 0, 0, 0);
  35. if(!writeFile) {
  36. fprintf(stderr, "Failed to open %s for writing!\n", writePath);
  37. exit(-1);
  38. }
  39. char* buffer = "Hello, World!";
  40. tSize num_written_bytes = hdfsWrite(fs, writeFile, (void*)buffer, strlen(buffer)+1);
  41. if (hdfsFlush(fs, writeFile)) {
  42. fprintf(stderr, "Failed to 'flush' %s\n", writePath);
  43. exit(-1);
  44. }
  45. hdfsCloseFile(fs, writeFile);* /
  46. * */