From 3f5a4d8752a2441acbea88a83785a98471d6c366 Mon Sep 17 00:00:00 2001 From: Gintas Grigelionis Date: Thu, 17 May 2018 22:04:23 +0200 Subject: [PATCH] =?UTF-8?q?Missed=20a=20piece=20of=20a=20file=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apache/tools/ant/util/StreamUtils.java | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) 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); + } }