me.snowdrop.istio.util.Utils Maven / Gradle / Ivy
Show all versions of istio-common Show documentation
/**
* Copyright 2018 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package me.snowdrop.istio.util;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* @author Christophe Laprun
*/
public class Utils {
public static String writeStreamToString(InputStream inputStream) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
try {
while ((length = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, length);
}
return outputStream.toString();
} catch (IOException e) {
throw new RuntimeException("Unable to read InputStream.", e);
}
}
}