Search in sources :

Example 41 with Closeable

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);
}
Also used : Closeable(java.io.Closeable)

Example 42 with Closeable

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);
    }
}
Also used : ColumnConfig(liquibase.change.ColumnConfig) SQLException(java.sql.SQLException) Closeable(java.io.Closeable) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) DatabaseException(liquibase.exception.DatabaseException)

Example 43 with Closeable

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();
}
Also used : Closeable(java.io.Closeable) Test(org.junit.Test)

Example 44 with Closeable

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();
}
Also used : Transaction(com.squareup.sqlbrite.BriteDatabase.Transaction) Closeable(java.io.Closeable) Test(org.junit.Test)

Example 45 with Closeable

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();
}
Also used : Path(java.nio.file.Path) MergingException(com.android.ide.common.res2.MergingException) Builder(com.google.devtools.build.android.ParsedAndroidData.Builder) Closeable(java.io.Closeable) ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService)

Aggregations

Closeable (java.io.Closeable)216 IOException (java.io.IOException)88 Test (org.junit.Test)56 ArrayList (java.util.ArrayList)29 File (java.io.File)26 HashMap (java.util.HashMap)12 VirtualFile (org.jboss.vfs.VirtualFile)12 URL (java.net.URL)9 Path (java.nio.file.Path)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 Map (java.util.Map)7 ISE (io.druid.java.util.common.ISE)6 InputStream (java.io.InputStream)6 MountHandle (org.jboss.as.server.deployment.module.MountHandle)6 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)6 ProgramController (co.cask.cdap.app.runtime.ProgramController)5 ProgramType (co.cask.cdap.proto.ProgramType)4 ProgramId (co.cask.cdap.proto.id.ProgramId)4 Pair (io.druid.java.util.common.Pair)4 FileOutputStream (java.io.FileOutputStream)4