-
-
Save olegkamuz/9bf4d4b61307adf7fb5ad7bb8ecad149 to your computer and use it in GitHub Desktop.
SpringBoot2FindAllImagesFix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
DirectoryStream
be used with try-with-resources to close after scanning the dir?