Github user ajantha-bhat commented on a diff in the pull request: https://github.com/apache/carbondata/pull/2384#discussion_r197638028 --- Diff: core/src/main/java/org/apache/carbondata/core/util/CarbonUtil.java --- @@ -3116,5 +3117,48 @@ public static void setLocalDictColumnsToWrapperSchema(List<ColumnSchema> columns } } } -} + /** + * Utility function to read a whole file as a string, + * Must not use this if the file is very huge. As it may result in memory exhaustion. + * @param filePath + * @return + */ + public static String readFromFile(String filePath) { + File file = new File(filePath); + URI uri = file.toURI(); + byte[] bytes; + try { + bytes = java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(uri)); + } catch (IOException e) { + e.printStackTrace(); + return "ERROR loading file " + filePath; + } + try { + return new String(bytes, "UTF-8"); + } catch (UnsupportedEncodingException e) { + return "ERROR while encoding to UTF-8 for file " + filePath; + } + } + + /** + * get list of file paths with requested extensions from the path + * @param carbonFile + * @param jsonFileList + * @param fileExtension + */ + public static void getFileList(CarbonFile carbonFile, List<String> jsonFileList, --- End diff -- ok. done
---