use of com.facebook.presto.localfile.LocalFileErrorCode.LOCAL_FILE_NO_FILES in project presto by prestodb.
the class DataLocation method files.
public List<File> files() {
checkState(location.exists(), "location %s doesn't exist", location);
if (!pattern.isPresent()) {
return ImmutableList.of(location);
}
checkState(location.isDirectory(), "location %s is not a directory", location);
try (DirectoryStream<Path> paths = newDirectoryStream(location.toPath(), pattern.get())) {
ImmutableList.Builder<File> builder = ImmutableList.builder();
for (Path path : paths) {
builder.add(path.toFile());
}
List<File> files = builder.build();
if (files.isEmpty()) {
throw new PrestoException(LOCAL_FILE_NO_FILES, "No matching files found in directory: " + location);
}
return files.stream().sorted((o1, o2) -> Long.compare(o2.lastModified(), o1.lastModified())).collect(Collectors.toList());
} catch (IOException e) {
throw new PrestoException(LOCAL_FILE_FILESYSTEM_ERROR, "Error listing files in directory: " + location, e);
}
}
Aggregations