public static byte[] readFully(InputStream is) throws IOException {
  byte[] buf=new byte[4096];
  ByteArrayOutputStream os=new ByteArrayOutputStream(4096);
  for (; ; ) {
    int bytesRead=is.read(buf);
    if (bytesRead == -1)     break;
    os.write(buf,0,bytesRead);
  }
  return os.toByteArray();
}

public static byte [ ] readFully ( InputStream is ) throws IOException { byte [ ] buf = new byte [ 4096 ] ; ByteArrayOutputStream os = new ByteArrayOutputStream ( 4096 ) ; for ( ; ; ) { int bytesRead = is . read ( buf ) ; if ( bytesRead == - 1 ) break ; os . write ( buf , 0 , bytesRead ) ; } return os . toByteArray ( ) ; }
reads entire resource from an input stream
