[java] Using try-with-resources to close the stream
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
+import java.util.stream.Stream;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
@@ -66,8 +67,8 @@ public boolean isDirectory() {
@Override
public Set<Resource> list() {
- try {
- return Files.list(base).map(PathResource::new).collect(toImmutableSet());
+ try (Stream<Path> files = Files.list(base)) {
+ return files.map(PathResource::new).collect(toImmutableSet());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
