public static int readFully(InputStream inStr,byte[] buf,int off,int len) throws IOException {
  int totalRead=0;
  while (totalRead < len) {
    int numRead=inStr.read(buf,off + totalRead,len - totalRead);
    if (numRead < 0) {
      break;
    }
    totalRead+=numRead;
  }
  return totalRead;
}

public static int readFully ( InputStream inStr , byte [ ] buf , int off , int len ) throws IOException { int totalRead = 0 ; while ( totalRead < len ) { int numRead = inStr . read ( buf , off + totalRead , len - totalRead ) ; if ( numRead < 0 ) { break ; } totalRead += numRead ; } return totalRead ; }
fully read in len ' s bytes of data into buf , or up to eof , whichever occurs first ,
