private static final int RESOURCE_CHARACTERISTICS = Spliterator.NONNULL & Spliterator.IMMUTABLE; static Stream streamOf(Supplier> iteratorSupplier) { return StreamSupport.stream( () -> Spliterators.spliteratorUnknownSize(iteratorSupplier.get(), RESOURCE_CHARACTERISTICS), RESOURCE_CHARACTERISTICS, false); } public Stream resources(String name) { return streamOf(() -> { try { // delegate to the enumeration method return getResources(name).asIterator(); } catch (IOException e) { throw new UncheckedIOException(e); } }); } public Stream systemResources(String name) { return streamOf(() -> { try { // delegate to the enumeration method return getSystemResources(name).asIterator(); } catch (IOException e) { throw new UncheckedIOException(e); } }); }