title: Android converting stream to byte array Out of Memory Exceptions
body: <p>I have ran into a situation where I am getting out of memory exceptions when trying to convert an input stream into a byte array. On newer Android phones it's no problem, but some of these cheaper models are experiencing it. Here is the method I'm using. Is there a more efficient way to do this?</p>
  
  <pre><code>public byte[] convertStreamToByteArray(InputStream is) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] buff = new byte[1024];
    int i = 0;
    while ((i = is.read(buff, 0, buff.length)) &gt; 0) {
      baos.write(buff, 0, i);
    }
    return baos.toByteArray();
  }
  </code></pre>