java - Creating an input stream object in Hadoop for reading a file -


i have file in hadoop filesystem , need create inputstream object in-order pass input parameter api apimethod(inputstreamobject).

i using below approach mentioned in definitive guide create input stream object not work.

class test {          static {             url.seturlstreamhandlerfactory(new fsurlstreamhandlerfactory());  }           inputstream in = null;          try {           in = new url("hdfs://host/path").openstream();           ioutils.copybytes(in, system.out, 4096, false);         object = new apimethod(in);         } {           ioutils.closestream(in); }   } 

please help.

if want read file hadoop,let's try approach. read file hadoop , write local path or print on screen.

filesystem filesystem = filesystem.get(conf);  path path = new path("/path/to/file");  fsdatainputstream in = filesystem.open(path); outputstream out = new bufferedoutputstream(new fileoutputstream(     new file(fileonlocal)));  byte[] b = new byte[1024]; int numbytes = 0; while ((numbytes = in.read(b)) > 0) {     out.write(b, 0, numbytes); }  in.close(); out.close(); filesystem.close(); 

Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -