BdioWriter implements Closeable { @Override public void close() throws IOException { if (closed.compareAndSet(false, true)) { try { closeStream(); } finally { entryStreams.close(); } } } BdioWriter(BdioMetadata metadata, StreamSupplier entryStreams); void start(); void next(Map<String, Object> node); @Override void close(); void closeEntry();  }
@Test public void idempotentClose() throws IOException { OutputStream out = mock(OutputStream.class); BdioWriter writer = new BdioWriter(metadata, new BdioFile(out)); writer.close(); writer.close(); verify(out, times(1)).close(); }