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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations