@Override protected void doClose() { delegate.close(); } }
@Override public void close() { for (CloseableIterator<?> reportIterator : closeables) { reportIterator.close(); } }
@Override protected void doClose() throws Exception { // iterator can be already closed by doNext(), but closing here ensures // that iterator is closed when it is not fully traversed. iterator.close(); for (AutoCloseable otherCloseable : otherCloseables) { otherCloseable.close(); } } }
@Override public void close() throws IOException { this.logsIterator.close(); this.buf = null; super.close(); } }
@Override public final void remove() { try { doRemove(); } catch (RuntimeException e) { close(); throw e; } }
@Override public boolean hasNext() { // Optimization to not call bufferNext() when already closed if (isClosed) { return false; } boolean hasNext = nextObject != null || bufferNext() != null; if (!hasNext) { close(); } return hasNext; }
private O bufferNext() { try { nextObject = doNext(); return nextObject; } catch (RuntimeException e) { close(); throw e; } }
static ScannerContextImpl from(CloseableIterator<ScannerReport.ContextProperty> it) { try { ImmutableMap.Builder<String, String> mapBuilder = ImmutableMap.builder(); while (it.hasNext()) { ScannerReport.ContextProperty prop = it.next(); mapBuilder.put(prop.getKey(), prop.getValue()); } return new ScannerContextImpl(mapBuilder.build()); } finally { it.close(); } } }
@Test public void close_closes_all_closeables() { LineReader r1 = mock(LineReader.class); LineReader r2 = mock(LineReader.class); CloseableIterator<Object> c1 = newCloseableIteratorMock(); CloseableIterator<Object> c2 = newCloseableIteratorMock(); SourceLineReadersFactory.LineReaders lineReaders = new SourceLineReadersFactory.LineReadersImpl(asList(r1, r2), null, asList(c1, c2)); lineReaders.close(); verify(c1).close(); verify(c2).close(); verifyNoMoreInteractions(c1, c2); verifyZeroInteractions(r1, r2); }
private static void consume(CloseableIterator<String> stringCloseableIterator) { try { while (stringCloseableIterator.hasNext()) { stringCloseableIterator.next(); } } finally { stringCloseableIterator.close(); } }
@Test public void verify_readComponentSyntaxHighlighting() { writer.writeComponentSyntaxHighlighting(COMPONENT_REF, of(SYNTAX_HIGHLIGHTING_1, SYNTAX_HIGHLIGHTING_2)); CloseableIterator<ScannerReport.SyntaxHighlightingRule> res = underTest.readComponentSyntaxHighlighting(COMPONENT_REF); assertThat(res).containsExactly(SYNTAX_HIGHLIGHTING_1, SYNTAX_HIGHLIGHTING_2); res.close(); }
@Test public void verify_readComponentCoverage() { writer.writeComponentCoverage(COMPONENT_REF, of(COVERAGE_1, COVERAGE_2)); CloseableIterator<ScannerReport.LineCoverage> res = underTest.readComponentCoverage(COMPONENT_REF); assertThat(res).containsExactly(COVERAGE_1, COVERAGE_2); res.close(); }
@Test public void verify_readFileSource() throws IOException { File file = writer.getSourceFile(COMPONENT_REF); FileUtils.writeLines(file, of("1", "2", "3")); CloseableIterator<String> res = underTest.readFileSource(COMPONENT_REF).get(); assertThat(res).containsExactly("1", "2", "3"); res.close(); }
private Duplication[] readDuplications(DefaultInputFile file, int expected) { assertThat(reader.readComponentDuplications(file.scannerId())).hasSize(expected); Duplication[] duplications = new Duplication[expected]; CloseableIterator<Duplication> dups = reader.readComponentDuplications(file.scannerId()); for (int i = 0; i < expected; i++) { duplications[i] = dups.next(); } dups.close(); return duplications; }
@Test public void verify_readAnalysisWarnings() { ScannerReport.AnalysisWarning warning1 = ScannerReport.AnalysisWarning.newBuilder().setText("warning 1").build(); ScannerReport.AnalysisWarning warning2 = ScannerReport.AnalysisWarning.newBuilder().setText("warning 2").build(); ImmutableList<ScannerReport.AnalysisWarning> warnings = of(warning1, warning2); writer.writeAnalysisWarnings(warnings); CloseableIterator<ScannerReport.AnalysisWarning> res = underTest.readAnalysisWarnings(); assertThat(res).containsExactlyElementsOf(warnings); res.close(); } }
@Override public void close() { for (CloseableIterator<?> reportIterator : closeables) { reportIterator.close(); } }
@Override public void close() throws IOException { this.logsIterator.close(); this.buf = null; super.close(); } }
@Override protected void doClose() throws Exception { // iterator can be already closed by doNext(), but closing here ensures // that iterator is closed when it is not fully traversed. iterator.close(); for (AutoCloseable otherCloseable : otherCloseables) { otherCloseable.close(); } } }
private O bufferNext() { try { nextObject = doNext(); return nextObject; } catch (RuntimeException e) { close(); throw e; } }
@Override public boolean hasNext() { // Optimization to not call bufferNext() when already closed if (isClosed) { return false; } boolean hasNext = nextObject != null || bufferNext() != null; if (!hasNext) { close(); } return hasNext; }