jadb/src/se/vidstige/jadb/Util.java

29 lines
835 B
Java

package se.vidstige.jadb;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
public class Util {
/**
* Convert an input stream to string
*
* @param inputStream input stream
*
* @return string representation of the input stream
*
* @throws IOException if an error ocurrs reading the input stream
*/
public static String inputStreamToString(InputStream inputStream) throws IOException {
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) != -1) {
result.write(buffer, 0, length);
}
return result.toString(StandardCharsets.UTF_8.name());
}
}