HdfsServiceImpl implements HdfsService { @Override public String read(Path path) throws RestException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try { IOUtils.copyBytes(getFileSystem().open(path), byteArrayOutputStream, configuration); } catch (FileNotFoundException e) { return null; } catch (IOException e) { throw new RestException(e); } return new String(byteArrayOutputStream.toByteArray(), UTF_8); } @Autowired  HdfsServiceImpl(Configuration configuration); @Override List<String> list(Path path); @Override String read(Path path); @Override void write(Path path, byte[] contents, String userMode, String groupMode, String otherMode); @Override boolean delete(Path path, boolean recursive); @Override boolean mkdirs(Path path);  }
@Test public void readShouldProperlyReadContents() throws Exception { String contents = "contents"; FileUtils.writeStringToFile(new File(testDir, "readTest.txt"), contents); assertEquals("contents", hdfsService.read(new Path(testDir, "readTest.txt"))); }