private byte[] streamToArray(InputStream stream) throws IOException {
  byte[] result=new byte[0];
  byte[] tmp=new byte[8192];
  int readCount;
  while ((readCount=stream.read(tmp)) > 0) {
    byte[] innerTmp=new byte[result.length + readCount];
    System.arraycopy(result,0,innerTmp,0,result.length);
    System.arraycopy(tmp,0,innerTmp,result.length,readCount);
    result=innerTmp;
  }
  stream.close();
  return result;
}

private byte [ ] streamToArray ( InputStream stream ) throws IOException { byte [ ] result = new byte [ 0 ] ; byte [ ] tmp = new byte [ 8192 ] ; int readCount ; while ( ( readCount = stream . read ( tmp ) ) > 0 ) { byte [ ] innerTmp = new byte [ result . length + readCount ] ; System . arraycopy ( result , 0 , innerTmp , 0 , result . length ) ; System . arraycopy ( tmp , 0 , innerTmp , result . length , readCount ) ; result = innerTmp ; } stream . close ( ) ; return result ; }
transforms passed stream into array of bytes .
