RFR: JDK-8161230 ClassLoader: add resource methods returning java.util.stream.Stream
Paul Sandoz
paul.sandoz at oracle.com
Wed Sep 7 19:09:59 UTC 2016
Hi Patrick,
I will sponsor this.
Given what Mandy says about the system class loader i think we can drop the method systemResources. There is some “race memory" not captured in the specification, which should be updated, as Mandy says.
Then…
1401 public Stream<URL> resources(String name) {
1402 return streamOf(() -> {
1403 try {
1404 return getResources(name).asIterator();
1405 } catch (IOException e) {
1406 throw new UncheckedIOException(e);
1407 }
1408 });
1409 }
1410
1411 private static final int RESOURCE_CHARACTERISTICS = Spliterator.NONNULL | Spliterator.IMMUTABLE;
1412
1413 static Stream<URL> streamOf(Supplier<Iterator<URL>> iteratorSupplier) {
1414 return StreamSupport.stream(
1415 () -> Spliterators.spliteratorUnknownSize(iteratorSupplier.get(), RESOURCE_CHARACTERISTICS),
1416 RESOURCE_CHARACTERISTICS, false);
1417 }
1418
… you can merge the suppliers e.g:
Supplier<Spliterator<URL>> si = () -> {
try {
return Spliterators.spliteratorUnknownSize(getResources(name).asIterator(), …);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
};
return StreamSupport.stream(si, …);
?
Paul.
> On 7 Sep 2016, at 11:38, Patrick Reinhart <patrick at reini.net> wrote:
>
> The current changes can be found here:
>
> http://cr.openjdk.java.net/~reinhapa/reviews/8161230/webrev.03
>
More information about the core-libs-dev
mailing list