public static int readBytes(InputStream in,byte[] byteArray) throws IOException {
  int totalBytesRead=0;
  int bytesRead=in.read(byteArray);
  while (bytesRead >= 0) {
    totalBytesRead+=bytesRead;
    if (totalBytesRead == byteArray.length) {
      break;
    }
    bytesRead=in.read(byteArray,totalBytesRead,byteArray.length - totalBytesRead);
  }
  return totalBytesRead;
}

public static int readBytes ( InputStream in , byte [ ] byteArray ) throws IOException { int totalBytesRead = 0 ; int bytesRead = in . read ( byteArray ) ; while ( bytesRead >= 0 ) { totalBytesRead += bytesRead ; if ( totalBytesRead == byteArray . length ) { break ; } bytesRead = in . read ( byteArray , totalBytesRead , byteArray . length - totalBytesRead ) ; } return totalBytesRead ; }
fills the supplied byte array with bytes read from the specified inputstream . this method will only stop reading when the byte array has been filled completely , or the end of the stream has been reached .
