/ImageService.java Secret
Created
June 6, 2020 14:45
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?