/** * Creates a new {@link Closer}. */ public static Closer create() { return new Closer(); }
public CloseableGrouperIterator( final Grouper<KeyType> grouper, final boolean sorted, final Function<Grouper.Entry<KeyType>, T> transformer, final Closeable closeable ) { this.transformer = transformer; this.iterator = grouper.iterator(sorted); this.closer = Closer.create(); closer.register(iterator); closer.register(closeable); }
/** * NOTE: This is NOT thread-safe with add... so make sure all the adding is DONE before closing */ @Override public void close() { super.close(); facts.clear(); indexAndOffsets.clear(); if (selectors != null) { selectors.clear(); } Closer c = Closer.create(); aggBuffers.forEach(c::register); try { c.close(); } catch (IOException e) { throw new RuntimeException(e); } aggBuffers.clear(); } }
final Closer closer = Closer.create(); if (fireDepartment.checkFirehoseV2()) { firehoseV2 = initFirehoseV2(metadata); closer.register(firehoseV2); success = runFirehoseV2(firehoseV2); } else { firehose = initFirehose(); closer.register(firehose); success = runFirehose(firehose); closer.register(() -> plumber.finishJob()); fireDepartment.getDataSchema().getDataSource() ).emit(); throw closer.rethrow(e); throw closer.rethrow(e); closer.close();
@Override public void close() throws IOException { closer.close(); } }
public static <T> CloseableIterator<T> concat(List<? extends CloseableIterator<? extends T>> iterators) { final Closer closer = Closer.create(); iterators.forEach(closer::register); final Iterator<T> innerIterator = Iterators.concat(iterators.iterator()); return wrap(innerIterator, closer); }
/** * Closes all {@code Closeable} instances that have been added to this {@code Closer}. If an * exception was thrown in the try block and passed to one of the {@code exceptionThrown} methods, * any exceptions thrown when attempting to close a closeable will be suppressed. Otherwise, the * <i>first</i> exception to be thrown from an attempt to close a closeable will be thrown and any * additional exceptions that are thrown after that will be suppressed. */ @Override public void close() throws IOException { Throwable throwable = thrown; // close closeables in LIFO order while (!stack.isEmpty()) { Closeable closeable = stack.removeFirst(); try { closeable.close(); } catch (Throwable e) { if (throwable == null) { throwable = e; } else { suppress(throwable, e); } } } if (thrown == null && throwable != null) { Throwables.propagateIfPossible(throwable, IOException.class); throw new AssertionError(throwable); // not possible } }
Closer closer = Closer.create(); try { final FileSmoosher v9Smoosher = new FileSmoosher(outDir); log.info("Using SegmentWriteOutMediumFactory[%s]", omf.getClass().getSimpleName()); SegmentWriteOutMedium segmentWriteOutMedium = omf.makeSegmentWriteOutMedium(outDir); closer.register(segmentWriteOutMedium); long startTime = System.currentTimeMillis(); Files.asByteSink(new File(outDir, "version.bin")).write(Ints.toByteArray(IndexIO.V9_VERSION)); mergers ); closer.register(timeAndDimsIterator); final GenericColumnSerializer timeWriter = setupTimeWriter(segmentWriteOutMedium, indexSpec); final ArrayList<GenericColumnSerializer> metricWriters = throw closer.rethrow(t); closer.close();
@Override public void close() throws IOException { closer.close(); } }
/** * Returns an input stream for a s3 object. The returned input stream is not thread-safe. */ @Override public InputStream openInputStream() throws IOException { try { if (s3Object == null) { // lazily promote to full GET s3Object = s3Client.getObject(objectSummary.getBucketName(), objectSummary.getKey()); } final InputStream in = s3Object.getObjectContent(); final Closer closer = Closer.create(); closer.register(in); closer.register(s3Object); return new FilterInputStream(in) { @Override public void close() throws IOException { closer.close(); } }; } catch (AmazonServiceException e) { throw new IOE(e, "Could not load S3 URI [%s]", uri); } }
public static <T> CloseableIterator<T> mergeSorted( List<? extends CloseableIterator<? extends T>> iterators, Comparator<T> comparator ) { Preconditions.checkNotNull(comparator); final Closer closer = Closer.create(); iterators.forEach(closer::register); final Iterator<T> innerIterator = Iterators.mergeSorted(iterators, comparator); return wrap(innerIterator, closer); }
/** * Closes all {@code Closeable} instances that have been added to this {@code Closer}. If an * exception was thrown in the try block and passed to one of the {@code exceptionThrown} methods, * any exceptions thrown when attempting to close a closeable will be suppressed. Otherwise, the * <i>first</i> exception to be thrown from an attempt to close a closeable will be thrown and any * additional exceptions that are thrown after that will be suppressed. */ @Override public void close() throws IOException { Throwable throwable = thrown; // close closeables in LIFO order while (!stack.isEmpty()) { Closeable closeable = stack.removeFirst(); try { closeable.close(); } catch (Throwable e) { if (throwable == null) { throwable = e; } else { suppress(throwable, e); } } } if (thrown == null && throwable != null) { Throwables.propagateIfPossible(throwable, IOException.class); throw new AssertionError(throwable); // not possible } }