Convert InputStream to String in android, java

public String convertStreamToString(InputStream is)

throws IOException {


// To convert the InputStream to String we use the

//[] buffer) method. We iterate until the

// Reader return -1 which means there's no more data to

// read. We use the StringWriter class to produce the string.


if (is != null) {

Writer writer = new StringWriter();


char[] buffer = new char[1024];

try {

Reader reader = new BufferedReader(

new InputStreamReader(is, "iso-8859-1"));

int n;

while ((n = != -1) {

writer.write(buffer, 0, n);


} finally {



return writer.toString();

} else {

return "";



.htaccess redirect from olddomain to newdomain

A friend of mine wanted to redirect an old domain to a new doman, he made a simple 301 redirect but as the server physical ip was the same he falled into an redirect loop between domains.

What he needed to fix that is an if condition in the rewrite rule, I made this snipplet for him.

RewriteBase /
RewriteCond %{HTTP_HOST} !$ [NC]
RewriteRule ^(.*)$$1 [L,R=301]