本文整理了Java中java.util.stream.Stream.close()
方法的一些代码示例,展示了Stream.close()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Stream.close()
方法的具体详情如下:
包路径:java.util.stream.Stream
类名称:Stream
方法名:close
暂无
代码示例来源:origin: gocd/gocd
@Override
public void close() {
if (null != stream) {
stream.close();
}
stream = null;
iterator = null;
}
代码示例来源:origin: wildfly/wildfly
@Override
public void close() throws RealmUnavailableException {
resultStream.close();
closeContext(dirContext);
}
};
代码示例来源:origin: speedment/speedment
/**
* Closes this stream, causing all close handlers for this stream pipeline
* to be called.
*
* @see AutoCloseable#close()
*/
@Override
public void close() {
inner.close();
}
代码示例来源:origin: AxonFramework/AxonFramework
@Override
public void close() {
closed = true;
if (eventStream != null) {
eventStream.close();
}
}
}
代码示例来源:origin: AxonFramework/AxonFramework
private void closePrivateStream() {
Optional.ofNullable(privateStream).ifPresent(stream -> {
privateStream = null;
privateIterator = null;
stream.close();
});
}
}
代码示例来源:origin: CalebFenton/simplify
private static String getClassName(File inputFile) throws FileNotFoundException {
try {
Path myPath = Paths.get(inputFile.toURI());
Stream<String> lines = Files.lines(myPath);
Optional<String> firstClassLine = lines.filter(s -> s.startsWith(".class ")).findFirst();
lines.close();
if (!firstClassLine.isPresent()) {
throw new RuntimeException("Missing class directive in " + inputFile);
}
String line = firstClassLine.get();
Matcher m = CLASS_PATTERN.matcher(line);
if (!m.find()) {
throw new RuntimeException("Strange class directive: " + line);
}
return m.group(1);
} catch (IOException e) {
throw new RuntimeException("Unable to read class name in " + inputFile, e);
}
}
代码示例来源:origin: google/guava
public void testConcat_refStream_closeIsPropagated_Stream_concat() {
// Just to demonstrate behavior of Stream::concat in the standard library
AtomicInteger closeCountB = new AtomicInteger(0);
Stream<String> streamB = Stream.of("b").onClose(closeCountB::incrementAndGet);
Stream<String> concatenated =
Stream.<Stream<String>>of(Stream.of("a"), streamB, Stream.empty(), Stream.of("c", "d"))
.reduce(Stream.empty(), Stream::concat);
assertThat(concatenated).containsExactly("a", "b", "c", "d").inOrder();
concatenated.close();
Truth.assertThat(closeCountB.get()).isEqualTo(1);
}
代码示例来源:origin: google/guava
private void testMapWithIndex_closeIsPropagated(Stream<String> source) {
AtomicInteger stringsCloseCount = new AtomicInteger();
Stream<String> strings = source.onClose(stringsCloseCount::incrementAndGet);
Stream<String> withIndex = Streams.mapWithIndex(strings, (str, i) -> str + ":" + i);
withIndex.close();
Truth.assertThat(stringsCloseCount.get()).isEqualTo(1);
}
代码示例来源:origin: google/guava
public void testConcat_refStream_closeIsPropagated_Stream_flatMap() {
// Just to demonstrate behavior of Stream::flatMap in the standard library
AtomicInteger closeCountB = new AtomicInteger(0);
Stream<String> streamB = Stream.of("b").onClose(closeCountB::incrementAndGet);
Stream<String> concatenated =
Stream.<Stream<String>>of(Stream.of("a"), streamB, Stream.empty(), Stream.of("c", "d"))
.flatMap(x -> x);
assertThat(concatenated).containsExactly("a", "b", "c", "d").inOrder();
concatenated.close();
// even without close, see doc for flatMap
Truth.assertThat(closeCountB.get()).isEqualTo(1);
}
代码示例来源:origin: google/guava
private void testMapWithIndex_longStream_closeIsPropagated(LongStream source) {
AtomicInteger longStreamCloseCount = new AtomicInteger();
LongStream longStream = source.onClose(longStreamCloseCount::incrementAndGet);
Stream<String> withIndex = Streams.mapWithIndex(longStream, (str, i) -> str + ":" + i);
withIndex.close();
Truth.assertThat(longStreamCloseCount.get()).isEqualTo(1);
}
代码示例来源:origin: google/guava
public void testZip_closeIsPropagated() {
AtomicInteger lettersCloseCount = new AtomicInteger();
Stream<String> letters = Stream.of("a", "b", "c").onClose(lettersCloseCount::incrementAndGet);
AtomicInteger numbersCloseCount = new AtomicInteger();
Stream<Integer> numbers = Stream.of(1, 2, 3).onClose(numbersCloseCount::incrementAndGet);
Stream<String> zipped = Streams.zip(letters, numbers, (a, b) -> a + ":" + b);
zipped.close();
Truth.assertThat(lettersCloseCount.get()).isEqualTo(1);
Truth.assertThat(numbersCloseCount.get()).isEqualTo(1);
}
代码示例来源:origin: google/guava
private void testMapWithIndex_intStream_closeIsPropagated(IntStream source) {
AtomicInteger intStreamCloseCount = new AtomicInteger();
IntStream intStream = source.onClose(intStreamCloseCount::incrementAndGet);
Stream<String> withIndex = Streams.mapWithIndex(intStream, (str, i) -> str + ":" + i);
withIndex.close();
Truth.assertThat(intStreamCloseCount.get()).isEqualTo(1);
}
代码示例来源:origin: google/guava
private void testMapWithIndex_doubleStream_closeIsPropagated(DoubleStream source) {
AtomicInteger doubleStreamCloseCount = new AtomicInteger();
DoubleStream doubleStream = source.onClose(doubleStreamCloseCount::incrementAndGet);
Stream<String> withIndex = Streams.mapWithIndex(doubleStream, (str, i) -> str + ":" + i);
withIndex.close();
Truth.assertThat(doubleStreamCloseCount.get()).isEqualTo(1);
}
代码示例来源:origin: google/guava
public void testConcat_refStream_closeIsPropagated() {
AtomicInteger closeCountB = new AtomicInteger(0);
Stream<String> streamB = Stream.of("b").onClose(closeCountB::incrementAndGet);
Stream<String> concatenated =
Streams.concat(Stream.of("a"), streamB, Stream.empty(), Stream.of("c", "d"));
assertThat(concatenated).containsExactly("a", "b", "c", "d").inOrder();
concatenated.close();
Truth.assertThat(closeCountB.get()).isEqualTo(1);
}
代码示例来源:origin: google/guava
() -> {
for (Stream<? extends T> stream : streams) {
stream.close();
代码示例来源:origin: spring-projects/spring-security
@Test
public void filterStreamWhenClosedThenUpstreamGetsClosed() {
final Stream<?> upstream = mock(Stream.class);
doReturn(Stream.<String>empty()).when(upstream).filter(any());
Expression expression = handler.getExpressionParser().parseExpression("true");
EvaluationContext context = handler.createEvaluationContext(authentication,
methodInvocation);
((Stream) handler.filter(upstream, expression, context)).close();
verify(upstream).close();
}
}
代码示例来源:origin: google/j2objc
() -> {
for (Stream<? extends T> stream : streams) {
stream.close();
代码示例来源:origin: wildfly/wildfly
() -> {
for (Stream<? extends T> stream : streams) {
stream.close();
代码示例来源:origin: prestodb/presto
() -> {
for (Stream<? extends T> stream : streams) {
stream.close();
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void basicStreamTest() {
Session session = openSession();
session.getTransaction().begin();
// mainly we want to make sure that closing the Stream releases the ScrollableResults too
assertThat( ( (SessionImplementor) session ).getJdbcCoordinator().getLogicalConnection().getResourceRegistry().hasRegisteredResources(), is( false ) );
final Stream<MyEntity> stream = session.createQuery( "from MyEntity", MyEntity.class ).stream();
assertThat( ( (SessionImplementor) session ).getJdbcCoordinator().getLogicalConnection().getResourceRegistry().hasRegisteredResources(), is( true ) );
stream.forEach( System.out::println );
assertThat( ( (SessionImplementor) session ).getJdbcCoordinator().getLogicalConnection().getResourceRegistry().hasRegisteredResources(), is( true ) );
stream.close();
assertThat( ( (SessionImplementor) session ).getJdbcCoordinator().getLogicalConnection().getResourceRegistry().hasRegisteredResources(), is( false ) );
session.getTransaction().commit();
session.close();
}
内容来源于网络,如有侵权,请联系作者删除!