Java File convertInputStreamToString() Utility Method

Java File convertInputStreamToString() Utility Method - Converts InputStream to a String.

Java File convertInputStreamToString() Utility Method - Converts InputStream to a String

/**
 * Converts InputStream to a String
 * @param in
 * @return
 * @throws IOException
 */
public static String convertInputStreamToString(final InputStream in ) throws IOException {
    ByteArrayOutputStream result = new ByteArrayOutputStream();
    byte[] buffer = new byte[1024];
    int length;
    while ((length = in .read(buffer)) != -1) {
        result.write(buffer, 0, length);
    }
    return result.toString(StandardCharsets.UTF_8.name());
}





Comments