Search in sources :

Example 66 with Closer

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

the class JsonPrinterTest method standardJsonPrinting.

@Test
public void standardJsonPrinting() throws Exception {
    Closer closer = Closer.create();
    try {
        ByteArrayOutputStream baos = closer.register(new ByteArrayOutputStream());
        PrintStream out = closer.register(new PrintStream(baos));
        new JsonPrinter(out).print(standardProcess());
        String result = new String(baos.toByteArray());
        assertThat(result).contains("\"url\":\"service:jmx:rmi:///jndi/rmi://host.example.net:4321/jmxrmi\"");
    } catch (Throwable t) {
        throw closer.rethrow(t);
    } finally {
        closer.close();
    }
}
Also used : Closer(com.google.common.io.Closer) PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 67 with Closer

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

the class HttpOutputWriter method consumeInputStreams.

private void consumeInputStreams(HttpURLConnection httpURLConnection) throws IOException {
    Closer closer = Closer.create();
    try {
        InputStream in = closer.register(httpURLConnection.getInputStream());
        InputStream err = closer.register(httpURLConnection.getErrorStream());
        copy(in, nullOutputStream());
        if (err != null)
            copy(err, nullOutputStream());
    } catch (Throwable t) {
        throw closer.rethrow(t);
    } finally {
        closer.close();
    }
}
Also used : Closer(com.google.common.io.Closer) InputStream(java.io.InputStream)

Example 68 with Closer

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

the class Slf4JOutputWriter method logValue.

private void logValue(Server server, Query query, List<String> typeNames, Result result) throws IOException {
    Object value = result.getValue();
    String resultAsString = resultSerializer.serialize(server, query, result);
    if (resultAsString == null) {
        return;
    }
    Closer closer = Closer.create();
    try {
        closer.register(MDC.putCloseable("server", computeAlias(server)));
        closer.register(MDC.putCloseable("metric", KeyUtils.getKeyString(server, query, result, typeNames, null)));
        closer.register(MDC.putCloseable("value", value.toString()));
        if (result.getKeyAlias() != null) {
            closer.register(MDC.putCloseable("resultAlias", result.getKeyAlias()));
        }
        closer.register(MDC.putCloseable("attributeName", result.getAttributeName()));
        closer.register(MDC.putCloseable("key", KeyUtils.getValueKey(result)));
        closer.register(MDC.putCloseable("epoch", valueOf(result.getEpoch())));
        logger.info(resultAsString);
    } catch (Throwable t) {
        throw closer.rethrow(t);
    } finally {
        closer.close();
    }
}
Also used : Closer(com.google.common.io.Closer) ToString(lombok.ToString)

Example 69 with Closer

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

the class DatagramChannelAllocator method deallocate.

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

Example 70 with Closer

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

the class ChannelWriter method close.

@Override
public void close() throws IOException {
    Closer closer = Closer.create();
    try {
        closer.register(channel);
        flush();
    } catch (Throwable t) {
        throw closer.rethrow(t);
    } finally {
        closer.close();
    }
}
Also used : Closer(com.google.common.io.Closer)

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