Search in sources :

Example 71 with Closer

use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project jmxtrans by jmxtrans.

the class SocketAllocator method deallocate.

@Override
public void deallocate(SocketPoolable poolable) throws Exception {
    Closer closer = Closer.create();
    try {
        closer.register(poolable.getSocket());
        closer.register(poolable.getWriter());
    } catch (Throwable t) {
        throw closer.rethrow(t);
    } finally {
        closer.close();
    }
}
Also used : Closer(com.google.common.io.Closer)

Example 72 with Closer

use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project jmxtrans by jmxtrans.

the class TCPEchoServer method start.

// server is only stopped when interrupted. Might be ugly, but good enough for a test server.
@SuppressWarnings("squid:S2189")
public void start() {
    checkState(thread == null, "Server already started");
    thread = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Closer closer = Closer.create();
                try {
                    server = closer.register(new ServerSocket(0));
                    while (true) {
                        processRequests(server);
                    }
                } catch (Throwable t) {
                    throw closer.rethrow(t);
                } finally {
                    closer.close();
                    server = null;
                }
            } catch (IOException ioe) {
                log.error("Exception in TCP echo server", ioe);
            }
        }
    });
    thread.start();
    try {
        synchronized (startSynchro) {
            startSynchro.wait(1000);
        }
    } catch (InterruptedException interrupted) {
        log.error("TCP Echo server seems to take too long to start", interrupted);
    }
}
Also used : Closer(com.google.common.io.Closer) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException)

Example 73 with Closer

use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project gradle by gradle.

the class DefaultBuildCacheController method close.

@Override
public void close() throws IOException {
    if (!closed) {
        closed = true;
        Closer closer = Closer.create();
        closer.register(local);
        closer.register(remote);
        closer.close();
    }
}
Also used : Closer(com.google.common.io.Closer)

Example 74 with Closer

use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project scheduling by ow2-proactive.

the class SchedulerClient method renewSession.

@Override
public void renewSession() throws NotConnectedException {
    Closer closer = Closer.create();
    try {
        LoginForm loginForm = new LoginForm();
        loginForm.setUsername(connectionInfo.getLogin());
        loginForm.setPassword(connectionInfo.getPassword());
        if (connectionInfo.getCredentialFile() != null) {
            FileInputStream inputStream = new FileInputStream(connectionInfo.getCredentialFile());
            closer.register(inputStream);
            loginForm.setCredential(inputStream);
        }
        sid = restApi().loginOrRenewSession(sid, loginForm);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        try {
            closer.close();
        } catch (IOException e) {
        // ignore
        }
    }
}
Also used : Closer(com.google.common.io.Closer) IOException(java.io.IOException) LoginForm(org.ow2.proactive_grid_cloud_portal.common.dto.LoginForm) FileInputStream(java.io.FileInputStream) KeyStoreException(java.security.KeyStoreException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) IOException(java.io.IOException) SchedulerException(org.ow2.proactive.scheduler.common.exception.SchedulerException) TimeoutException(java.util.concurrent.TimeoutException) JobAlreadyFinishedException(org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException) SignalApiException(org.ow2.proactive.scheduler.signal.SignalApiException)

Example 75 with Closer

use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project scheduling by ow2-proactive.

the class VFSZipper method zip.

public static void zip(FileObject file, OutputStream out) throws IOException {
    Closer closer = Closer.create();
    try {
        closer.register(out);
        InputStream in = file.getContent().getInputStream();
        closer.register(in);
        ByteStreams.copy(in, out);
    } catch (IOException ioe) {
        throw closer.rethrow(ioe);
    } finally {
        closer.close();
    }
}
Also used : Closer(com.google.common.io.Closer) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException)

Aggregations

Closer (com.google.common.io.Closer)213 IOException (java.io.IOException)95 File (java.io.File)26 Test (org.testng.annotations.Test)21 Path (org.apache.hadoop.fs.Path)18 Test (org.junit.Test)18 Properties (java.util.Properties)16 Closer (org.apache.flink.shaded.guava30.com.google.common.io.Closer)16 FileOutputStream (java.io.FileOutputStream)15 ArrayList (java.util.ArrayList)15 WorkUnit (org.apache.gobblin.source.workunit.WorkUnit)13 FileInputStream (java.io.FileInputStream)12 InputStream (java.io.InputStream)12 OutputStream (java.io.OutputStream)12 Map (java.util.Map)12 ByteArrayInputStream (java.io.ByteArrayInputStream)10 DataInputStream (java.io.DataInputStream)10 UncheckedIOException (java.io.UncheckedIOException)10 Configuration (org.apache.hadoop.conf.Configuration)10 Text (org.apache.hadoop.io.Text)9