All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.heroku.agent.metrics.Utils Maven / Gradle / Ivy

Go to download

This artifact is for use with the JVM Runtime Metrics features. It is a lightweight Java agent that uses a Prometheus Java client to report metrics.

The newest version!
package com.heroku.agent.metrics;

import java.io.*;
import java.nio.charset.StandardCharsets;

public final class Utils {
  /**
   * Fully reads the given {@link InputStream} as a UTF-8 encoded string.
   *
   * @param inputStream The stream to read.
   * @return The data from the given stream, interpreted as a UTF-8 string.
   * @throws IOException If an IO related error occurred.
   */
  public static String readAllUtf8(InputStream inputStream) throws IOException {
    ByteArrayOutputStream result = new ByteArrayOutputStream();

    byte[] buffer = new byte[1024];

    int lastByteAmountRead;
    while ((lastByteAmountRead = inputStream.read(buffer)) != -1) {
      result.write(buffer, 0, lastByteAmountRead);
    }

    return result.toString(StandardCharsets.UTF_8.name());
  }

  private Utils() {}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy