mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 11:07:06 +00:00
(fix) NoSuchFileException when reading dimension file (#1813)
This commit is contained in:
@@ -156,8 +156,13 @@ public class FileHandlerImpl implements FileHandler {
|
|||||||
*/
|
*/
|
||||||
private List<DictValueResp> getFileData(String filePath, Integer startLine, Integer endLine) {
|
private List<DictValueResp> getFileData(String filePath, Integer startLine, Integer endLine) {
|
||||||
List<DictValueResp> fileData = new ArrayList<>();
|
List<DictValueResp> fileData = new ArrayList<>();
|
||||||
|
Path path = Paths.get(filePath);
|
||||||
|
if (!Files.exists(path)) {
|
||||||
|
log.warn("[getFileData] File does not exist: {}", getAbsolutePath(filePath));
|
||||||
|
return fileData;
|
||||||
|
}
|
||||||
|
|
||||||
try (Stream<String> lines = Files.lines(Paths.get(filePath))) {
|
try (Stream<String> lines = Files.lines(path)) {
|
||||||
fileData = lines.skip(startLine - 1).limit(endLine - startLine + 1)
|
fileData = lines.skip(startLine - 1).limit(endLine - startLine + 1)
|
||||||
.map(lineStr -> convert2Resp(lineStr)).filter(line -> Objects.nonNull(line))
|
.map(lineStr -> convert2Resp(lineStr)).filter(line -> Objects.nonNull(line))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
@@ -181,7 +186,13 @@ public class FileHandlerImpl implements FileHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Long getFileLineNum(String filePath) {
|
private Long getFileLineNum(String filePath) {
|
||||||
try (Stream<String> lines = Files.lines(Paths.get(filePath))) {
|
Path path = Paths.get(filePath);
|
||||||
|
if (!Files.exists(path)) {
|
||||||
|
log.warn("[getFileData] File does not exist: {}", getAbsolutePath(filePath));
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
|
||||||
|
try (Stream<String> lines = Files.lines(path)) {
|
||||||
Long lineCount = lines.count();
|
Long lineCount = lines.count();
|
||||||
return lineCount;
|
return lineCount;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user