@Override public void close() { if (null != stream) { stream.close(); } stream = null; iterator = null; }
@Override public void close() throws RealmUnavailableException { resultStream.close(); closeContext(dirContext); } };
/** * Closes this stream, causing all close handlers for this stream pipeline * to be called. * * @see AutoCloseable#close() */ @Override public void close() { inner.close(); }
@Override public void close() { closed = true; if (eventStream != null) { eventStream.close(); } } }
private void closePrivateStream() { Optional.ofNullable(privateStream).ifPresent(stream -> { privateStream = null; privateIterator = null; stream.close(); }); } }
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); } }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
() -> { for (Stream<? extends T> stream : streams) { stream.close();
@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(); } }
() -> { for (Stream<? extends T> stream : streams) { stream.close();
() -> { for (Stream<? extends T> stream : streams) { stream.close();
() -> { for (Stream<? extends T> stream : streams) { stream.close();
@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(); }