Example usage for com.google.common.io Closer close

List of usage examples for com.google.common.io Closer close

Introduction

In this page you can find the example usage for com.google.common.io Closer close.

Prototype

@Override
public void close() throws IOException 

Source Link

Document

Closes all Closeable instances that have been added to this Closer .

Usage

From source file:alluxio.worker.block.BlockMasterClientPool.java

@Override
public void close() throws IOException {
    BlockMasterClient client;/*  w w  w  . j a  v a 2s .  com*/
    Closer closer = Closer.create();
    while ((client = mClientList.poll()) != null) {
        closer.register(client);
    }
    closer.close();
}

From source file:alluxio.client.file.FileSystemMasterClientPool.java

@Override
public void close() throws IOException {
    FileSystemMasterClient client;//from   w w  w .j  av a2 s  .c om
    Closer closer = Closer.create();
    while ((client = mClientList.poll()) != null) {
        closer.register(client);
    }
    closer.close();
}

From source file:com.moz.fiji.commons.monitoring.CompoundNotifier.java

/** {@inheritDoc} */
@Override// w w w  . jav a2  s  . co  m
public void close() throws IOException {
    final Closer closer = Closer.create();
    for (final Notifier notifier : mNotifiers) {
        closer.register(notifier);
    }
    closer.close();
}

From source file:net.derquinse.common.io.BytesTransformer.java

/** Transforms a stream of bytes. */
public void transform(InputStream input, ByteSink output) throws IOException {
    checkInput(input);/*from ww w .  j a va  2 s. c  om*/
    checkOutput(output);
    final Closer closer = Closer.create();
    try {
        transform(input, closer.register(output.openStream()));
    } finally {
        closer.close();
    }
}

From source file:net.derquinse.common.io.BytesTransformer.java

/** Transforms a byte source. */
public void transform(ByteSource input, OutputStream output) throws IOException {
    checkInput(input);/*from   ww w  . j a  va 2 s  . c  o m*/
    checkOutput(output);
    final Closer closer = Closer.create();
    try {
        transform(closer.register(input.openStream()), output);
    } finally {
        closer.close();
    }
}

From source file:eu.interedition.text.index.IndexServiceBase.java

@Override
protected void startUp() throws Exception {
    if (LOG.isLoggable(Level.INFO)) {
        LOG.log(Level.INFO, "Starting {0}", getClass().getName());
    }//  w  w w  .  ja v a2s .  c o  m
    final Closer closer = Closer.create();
    try {
        closer.register(writer()).commit();
    } finally {
        closer.close();
    }
}

From source file:org.glowroot.agent.live.JvmTool.java

private static <T> T runExternalAttach(long pid, String methodName, InputStreamProcessor<T> processor,
        @Nullable File glowrootJarFile) throws Exception {
    List<String> command = buildCommand(pid, methodName, glowrootJarFile);
    ProcessBuilder processBuilder = new ProcessBuilder(command);
    Process process = processBuilder.start();
    Closer closer = Closer.create();
    ErrorStreamReader errorStreamReader;
    T result = null;/*  ww w .j av  a  2  s . com*/
    Exception processingException = null;
    try {
        InputStream in = closer.register(process.getInputStream());
        InputStream err = closer.register(process.getErrorStream());
        errorStreamReader = new ErrorStreamReader(err);
        Thread errorStreamReaderThread = new Thread(errorStreamReader);
        errorStreamReaderThread.setName("Glowroot-JVM-Tool-Error-Stream-Reader");
        errorStreamReaderThread.setDaemon(true);
        errorStreamReaderThread.start();
        try {
            result = processAndClose(in, processor);
        } catch (Exception e) {
            processingException = e;
        } catch (Throwable t) {
            processingException = new RuntimeException(t);
        }
        errorStreamReaderThread.join();
    } catch (Throwable t) {
        throw closer.rethrow(t);
    } finally {
        closer.close();
    }
    int status = process.waitFor();
    if (status == UNAVAILABLE_DUE_TO_RUNNING_IN_JRE_STATUS) {
        throw new UnavailableDueToRunningInJreException();
    } else if (status == UNAVAILABLE_PROBABLY_DUE_TO_DOCKER_PID_ONE_STATUS) {
        throw new UnavailableDueToDockerAlpinePidOneException();
    } else if (status != 0) {
        logger.error("error occurred while trying to run jvm tool:\n{}\n{}", Joiner.on(' ').join(command),
                errorStreamReader.getOutput().trim());
        throw new IllegalStateException("Error occurred while trying to run jvm tool");
    }
    if (result == null) {
        throw checkNotNull(processingException);
    }
    return result;
}

From source file:gobblin.compaction.HdfsWriter.java

public void write(String text) throws IOException {
    String dirInHdfs = getDirInHdfs();
    this.fileSystem.mkdirs(new Path(dirInHdfs));

    Closer closer = Closer.create();
    try {//from   ww w .  j a  va  2 s  .c  o m
        FSDataOutputStream fout = closer.register(this.fileSystem.create(new Path(filePathInHdfs)));
        fout.writeChars(text);
    } finally {
        closer.close();
    }
}

From source file:com.googlecode.jmxtrans.model.output.support.pool.ChannelWriter.java

@Override
public void close() throws IOException {
    Closer closer = Closer.create();
    try {//  w w w.  ja va2s  .  c o  m
        closer.register(channel);
        flush();
    } catch (Throwable t) {
        throw closer.rethrow(t);
    } finally {
        closer.close();
    }
}

From source file:net.derquinse.common.io.BytesTransformer.java

/** Transforms a byte source. */
public void transform(ByteSource input, ByteSink output) throws IOException {
    checkInput(input);/*from  w ww  .  j a  v  a 2s . com*/
    checkOutput(output);
    final Closer closer = Closer.create();
    try {
        transform(closer.register(input.openStream()), closer.register(output.openStream()));
    } finally {
        closer.close();
    }
}