@Test public void testContentOfHdfsFileNoContent() { Path filePath = new Path(Constants.TONY_CORE_SRC + "test/resources/empty.txt"); assertEquals(HdfsUtils.contentOfHdfsFile(fs, filePath), ""); }
public static String contentOfHdfsFile(FileSystem fs, Path filePath) { StringBuilder fileContent = new StringBuilder(); try (FSDataInputStream inStrm = fs.open(filePath); BufferedReader bufReader = new BufferedReader(new InputStreamReader(inStrm, StandardCharsets.UTF_8))) { String line; while ((line = bufReader.readLine()) != null) { fileContent.append(line); } return fileContent.toString(); } catch (IOException e) { LOG.error("Couldn't read content of file from HDFS", e); return ""; } }
HdfsUtils { public static String contentOfHdfsFile(FileSystem fs, Path filePath) { StringBuilder fileContent = new StringBuilder(); try (FSDataInputStream inStrm = fs.open(filePath); BufferedReader bufReader = new BufferedReader(new InputStreamReader(inStrm, StandardCharsets.UTF_8))) { String line; while ((line = bufReader.readLine()) != null) { fileContent.append(line); } return fileContent.toString(); } catch (IOException e) { LOG.error("Couldn't read content of file from HDFS", e); return ""; } } }
HdfsUtils { public static String contentOfHdfsFile(FileSystem fs, Path filePath) { StringBuilder fileContent = new StringBuilder(); try (FSDataInputStream inStrm = fs.open(filePath); BufferedReader bufReader = new BufferedReader(new InputStreamReader(inStrm, StandardCharsets.UTF_8))) { String line; while ((line = bufReader.readLine()) != null) { fileContent.append(line); } return fileContent.toString(); } catch (IOException e) { LOG.error("Couldn't read content of file from HDFS", e); return ""; } } private  HdfsUtils(); }
HdfsUtils { public static String contentOfHdfsFile(FileSystem fs, Path filePath) { StringBuilder fileContent = new StringBuilder(); try (FSDataInputStream inStrm = fs.open(filePath); BufferedReader bufReader = new BufferedReader(new InputStreamReader(inStrm, StandardCharsets.UTF_8))) { String line; while ((line = bufReader.readLine()) != null) { fileContent.append(line); } return fileContent.toString(); } catch (IOException e) { LOG.error("Couldn't read content of file from HDFS", e); return ""; } } private  HdfsUtils(); static boolean pathExists(FileSystem fs, Path filePath); static String contentOfHdfsFile(FileSystem fs, Path filePath); static String getLastComponent(String path); @VisibleForTesting static boolean isJobFolder(Path p, String regex); static List<FileStatus> getDirectories(FileSystem fs, Path path); static Path getJobDirPath(FileSystem fs, Path curr, String applicationId); static List<Path> getJobDirs(FileSystem fs, Path curr, String regex); static void copySrcToDest(Path src, Path dst, Configuration conf); }
HdfsUtils { public static String contentOfHdfsFile(FileSystem fs, Path filePath) { StringBuilder fileContent = new StringBuilder(); try (FSDataInputStream inStrm = fs.open(filePath); BufferedReader bufReader = new BufferedReader(new InputStreamReader(inStrm, StandardCharsets.UTF_8))) { String line; while ((line = bufReader.readLine()) != null) { fileContent.append(line); } return fileContent.toString(); } catch (IOException e) { LOG.error("Couldn't read content of file from HDFS", e); return ""; } } private  HdfsUtils(); static boolean pathExists(FileSystem fs, Path filePath); static String contentOfHdfsFile(FileSystem fs, Path filePath); static String getLastComponent(String path); @VisibleForTesting static boolean isJobFolder(Path p, String regex); static List<FileStatus> getDirectories(FileSystem fs, Path path); static Path getJobDirPath(FileSystem fs, Path curr, String applicationId); static List<Path> getJobDirs(FileSystem fs, Path curr, String regex); static void copySrcToDest(Path src, Path dst, Configuration conf);  }