use of java.io.Closeable in project flink by apache.
the class SafetyNetCloseableRegistry method doRegister.
@Override
protected void doRegister(WrappingProxyCloseable<? extends Closeable> wrappingProxyCloseable, Map<Closeable, PhantomDelegatingCloseableRef> closeableMap) throws IOException {
assert Thread.holdsLock(getSynchronizationLock());
Closeable innerCloseable = WrappingProxyUtil.stripProxy(wrappingProxyCloseable.getWrappedDelegate());
if (null == innerCloseable) {
return;
}
PhantomDelegatingCloseableRef phantomRef = new PhantomDelegatingCloseableRef(wrappingProxyCloseable, this, REAPER_THREAD.referenceQueue);
closeableMap.put(innerCloseable, phantomRef);
}
use of java.io.Closeable in project liquibase by liquibase.
the class ExecutablePreparedStatementBase method execute.
@Override
public void execute(PreparedStatementFactory factory) throws DatabaseException {
// build the sql statement
List<ColumnConfig> cols = new ArrayList<ColumnConfig>(getColumns().size());
String sql = generateSql(cols);
log.info("Prepared statement: " + sql);
log.debug("Number of columns = " + cols.size());
// create prepared statement
PreparedStatement stmt = factory.create(sql);
try {
// attach params
// index starts from 1
int i = 1;
for (ColumnConfig col : cols) {
log.debug("Applying column parameter = " + i + " for column " + col.getName());
applyColumnParameter(stmt, i, col);
i++;
}
// trigger execution
stmt.execute();
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
for (Closeable closeable : closeables) {
StreamUtil.closeQuietly(closeable);
}
JdbcUtils.closeStatement(stmt);
}
}
use of java.io.Closeable in project okhttp by square.
the class MockWebServerTest method closeViaClosable.
@Test
public void closeViaClosable() throws IOException {
Closeable server = new MockWebServer();
server.close();
}
use of java.io.Closeable in project sqlbrite by square.
the class BriteDatabaseTest method transactionIsCloseable.
@Test
public void transactionIsCloseable() throws IOException {
db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).subscribe(o);
o.assertCursor().hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").isExhausted();
Transaction transaction = db.newTransaction();
//noinspection UnnecessaryLocalVariable
// Verify type is implemented.
Closeable closeableTransaction = transaction;
try {
db.insert(TABLE_EMPLOYEE, employee("john", "John Johnson"));
db.insert(TABLE_EMPLOYEE, employee("nick", "Nick Nickers"));
transaction.markSuccessful();
} finally {
closeableTransaction.close();
}
o.assertCursor().hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").hasRow("john", "John Johnson").hasRow("nick", "Nick Nickers").isExhausted();
}
use of java.io.Closeable in project bazel by bazelbuild.
the class AndroidResourceProcessor method deserializeSymbolsToData.
/** Deserializes a list of serialized resource paths to a {@link ParsedAndroidData}. */
public ParsedAndroidData deserializeSymbolsToData(List<Path> symbolPaths) throws IOException, MergingException {
AndroidDataDeserializer deserializer = AndroidDataDeserializer.create();
final ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(15));
final Builder deserializedDataBuilder = ParsedAndroidData.Builder.newBuilder();
try (Closeable closeable = ExecutorServiceCloser.createWith(executorService)) {
List<ListenableFuture<Boolean>> deserializing = new ArrayList<>();
for (final Path symbolPath : symbolPaths) {
deserializing.add(executorService.submit(new Deserialize(deserializer, symbolPath, deserializedDataBuilder)));
}
FailedFutureAggregator<MergingException> aggregator = FailedFutureAggregator.createForMergingExceptionWithMessage("Failure(s) during dependency parsing");
aggregator.aggregateAndMaybeThrow(deserializing);
}
return deserializedDataBuilder.build();
}
Aggregations