A utility function to convert an InputStream to String.
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class StringUtils {
private StringUtils() { /* No op */ }
public static String from(InputStream is) {
byte[] buffer = new byte[1024];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
for (int count = is.read(buffer); count != -1; count = is.read(buffer)) {
baos.write(buffer, 0, count);
}
baos.close();
return new String(baos.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}