Skip to content

Instantly share code, notes, and snippets.

@olegkamuz
Created June 6, 2020 14:45
Show Gist options
  • Save olegkamuz/9bf4d4b61307adf7fb5ad7bb8ecad149 to your computer and use it in GitHub Desktop.
Save olegkamuz/9bf4d4b61307adf7fb5ad7bb8ecad149 to your computer and use it in GitHub Desktop.
SpringBoot2FindAllImagesFix
public Flux<Image> findAllImages() {
try {
return Flux.fromStream(
StreamSupport.stream(Files.newDirectoryStream(Paths.get(UPLOAD_ROOT)).spliterator(), true)
.map(path -> new Image(String.valueOf(path.hashCode()), path.getFileName().toString())));
} catch (IOException e) {
return Flux.empty();
}
}
@dotland
Copy link

dotland commented Oct 13, 2022

  1. Does this stream processing represent a delayed action?
  2. Shouldn't DirectoryStream be used with try-with-resources to close after scanning the dir?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment