title: Creating an input stream object in Hadoop for reading a file
body: <p>I have a file in my Hadoop filesystem and I need to create an InputStream object in-order to pass it as an input parameter to another API as <code>ApiMethod(inputstreamObject)</code>.</p>
  
  <p>I am using below approach as mentioned in Definitive Guide to create an input stream object but does not work.</p>
  
  <pre><code>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);
          } finally {  
          IOUtils.closeStream(in); } 
  
  }
  </code></pre>
  
  <p>Please help.</p>