diff --git a/src/main/org/apache/tools/ant/util/StreamUtils.java b/src/main/org/apache/tools/ant/util/StreamUtils.java index f64f4120a..0f0950c8e 100644 --- a/src/main/org/apache/tools/ant/util/StreamUtils.java +++ b/src/main/org/apache/tools/ant/util/StreamUtils.java @@ -1,6 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ package org.apache.tools.ant.util; import java.util.Enumeration; +import java.util.Iterator; import java.util.Spliterator; import java.util.Spliterators; import java.util.function.Consumer; @@ -26,8 +44,23 @@ public class StreamUtils { return false; } public void forEachRemaining(Consumer action) { - while(e.hasMoreElements()) action.accept(e.nextElement()); + while (e.hasMoreElements()) { + action.accept(e.nextElement()); + } } }, false); } + + /** + * Turn Iterator into a Stream + * + * @param Iterator type + * @param i Iterator + * @return Stream + */ + public static Stream iteratorAsStream(Iterator i) { + return StreamSupport.stream( + Spliterators.spliteratorUnknownSize(i, Spliterator.ORDERED), + false); + } }