Does not read the entire input stream in android
<p>I am trying to read a response from a server and transform it from InputStream to String but something goes wrong and i cannot see right now why.</p>

<pre><code>InputStream is = entity.getContent();
FileOutputStream folder = new FileOutputStream(
            Environment.getExternalStorageDirectory()
                    + "/test.xml");
try {
byte[] buf = new byte[1048576];
int current = 0;
int newCurrent = 0;
while ((current = is.read(buf)) != -1) {
    newCurrent = newCurrent + current;
    folder.write(buf, 0, current);
}
System.out.println("returned folder" + folder);
folder.flush();
} catch (IOException e) {
        System.out.println("error on reading input: " + e.getMessage());
    }
</code></pre>

<p>This is the error:</p>

<pre><code>    error on reading input: Socket closed
</code></pre>

<p>This is the error I get and another problem that i don't understand is why it does not read the entire content from InputStream(maybe because it's all in one line?).
Thanks.</p>
