public static int read(InputStream in,byte[] b,int off,int len) throws IOException {
  int cnt=0;
  while (cnt < len) {
    int readOnce=in.read(b,off + cnt,len - cnt);
    if (readOnce <= 0)     break;
    cnt+=readOnce;
  }
  return cnt;
}

public static int read ( InputStream in , byte [ ] b , int off , int len ) throws IOException { int cnt = 0 ; while ( cnt < len ) { int readOnce = in . read ( b , off + cnt , len - cnt ) ; if ( readOnce <= 0 ) break ; cnt += readOnce ; } return cnt ; }
reads len bytes from in and places in b starting at off and returns len . input : in should have at least len bytes ; if not , then - 1 is returned if no bytes are available ( end of stream ) or all of the remaining bytes are placed in b , starting at off and this number is returned . output : the number of bytes read is returned or - 1 is the stream is empty . this should be used instead of the read provided by any of the inputstreams ; this is because for such streams ( e . g . bufferedinputstream and gzipoutputstream ) if you use the given read routines to read in x bytes , but the buffer has some , but not enough bytes , then you don ' t get them all ; you just get what the buffer has . this version fixes that problem .
