public static String getResourceAsString(String name) { try { return toString(getResourceAsStream(name)); } catch (IOException e) { throw new RuntimeException(e); } }
public static void sendConfigurationMapping(ElasticsearchClient elasticsearchClient) { final String mappingJson; try { mappingJson = IOUtils.toString(IOUtils.getResourceAsStream("stagemonitor-configuration-elasticsearch-mapping.json")); elasticsearchClient.sendMappingTemplate(mappingJson, "stagemonitor-configuration"); } catch (IOException e) { logger.warn("Suppressed exception:", e); } }
@Override public T handleResponse(HttpRequest<?> httpRequest, InputStream is, Integer statusCode, IOException e) throws IOException { if (statusCode != null && statusCode >= 400) { logger.warn(httpRequest.getSafeUrl() + ": " + statusCode + " " + IOUtils.toString(is)); } else { IOUtils.consumeAndClose(is); } return null; } }
@Test public void testToString() throws IOException { final ByteArrayInputStream bios = new ByteArrayInputStream("test".getBytes()); Assert.assertEquals("test", IOUtils.toString(bios)); }
private void onFlushError(Integer responseCode, InputStream inputStream, @Nullable IOException e) { // TODO read accepted, dropped and invalid onConnectionError(responseCode, currentlyTransmitting, 0); if (e != null) { logger.error("Error sending data to APM server: {}, response code is {}", e.getMessage(), responseCode); logger.debug("Sending payload to APM server failed", e); } if (logger.isWarnEnabled()) { try { logger.warn(IOUtils.toString(inputStream)); } catch (IOException e1) { logger.warn(e1.getMessage(), e); } finally { IOUtils.closeQuietly(inputStream); } } else { // in order to be able to reuse the underlying TCP connections, // the input stream must be consumed and closed // see also https://docs.oracle.com/javase/8/docs/technotes/guides/net/http-keepalive.html IOUtils.consumeAndClose(inputStream); } }