(FileSystem fs, String fileName)
| 391 | } |
| 392 | |
| 393 | static public String[] readOutput(FileSystem fs, String fileName) throws IOException { |
| 394 | if(Util.WINDOWS){ |
| 395 | fileName = fileName.replace('\\','/'); |
| 396 | } |
| 397 | Path path = new Path(fileName); |
| 398 | if(!fs.exists(path)) { |
| 399 | throw new IOException("Path " + fileName + " does not exist on the FileSystem"); |
| 400 | } |
| 401 | FileStatus fileStatus = fs.getFileStatus(path); |
| 402 | FileStatus[] files; |
| 403 | if (fileStatus.isDir()) { |
| 404 | files = fs.listStatus(path, new PathFilter() { |
| 405 | @Override |
| 406 | public boolean accept(Path p) { |
| 407 | return !p.getName().startsWith("_"); |
| 408 | } |
| 409 | }); |
| 410 | } else { |
| 411 | files = new FileStatus[] { fileStatus }; |
| 412 | } |
| 413 | List<String> result = new ArrayList<String>(); |
| 414 | for (FileStatus f : files) { |
| 415 | FSDataInputStream stream = fs.open(f.getPath()); |
| 416 | BufferedReader br = new BufferedReader(new InputStreamReader(stream, "UTF-8")); |
| 417 | String line; |
| 418 | while ((line = br.readLine()) != null) { |
| 419 | result.add(line); |
| 420 | } |
| 421 | br.close(); |
| 422 | } |
| 423 | return result.toArray(new String[result.size()]); |
| 424 | } |
| 425 | |
| 426 | /** |
| 427 | * Helper to create a dfs file on the MiniCluster dfs. This returns an |
no test coverage detected