
com.speedment.runtime.core.stream.AutoClosingStream Maven / Gradle / Ivy
package com.speedment.runtime.core.stream;
import com.speedment.runtime.core.internal.stream.autoclose.AutoClosingReferenceStream;
import java.util.stream.Stream;
public interface AutoClosingStream extends Stream {
/**
* Creates an returns a new Stream that automatically will invoke its {@link Stream#close()} method
* whenever a terminating operation is invoked and where the stream elements are obtained from the given
* {@code stream}.
*
* @param Stream type
* @param stream to wrap
*
* @return a new Stream that automatically will invoke its {@link Stream#close()} method
* whenever a terminating operation is invoked and where the stream elements are obtained from the given
* {@code stream}
*
* @throws NullPointerException if the provided {@code stream} is {@code null}
*/
static Stream of(Stream stream) {
return new AutoClosingReferenceStream<>(stream);
}
/**
* Creates an returns a new Stream that automatically will invoke its {@link Stream#close()} method
* whenever a terminating operation is invoked and where the stream elements are obtained from the given
* {@code stream}.
*
* @param Stream type
* @param stream to wrap
* @param allowStreamIteratorAndSpliterator if the methods {@link Stream#iterator()} and
* {@link Stream#spliterator()} are allowed.
*
* @return a new Stream that automatically will invoke its {@link Stream#close()} method
* whenever a terminating operation is invoked and where the stream elements are obtained from the given
* {@code stream}
*
* @throws NullPointerException if the provided {@code stream} is {@code null}
*/
static Stream of(
final Stream stream,
final boolean allowStreamIteratorAndSpliterator
) {
return new AutoClosingReferenceStream<>(stream, allowStreamIteratorAndSpliterator);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy