protected int readFully(InputStream in,byte buffer[],int offset,int len) throws java.io.IOException {
  for (int i=0; i < len; i++) {
    int q=in.read();
    if (q == -1)     return ((i == 0) ? -1 : i);
    buffer[i + offset]=(byte)q;
  }
  return len;
}

protected int readFully ( InputStream in , byte buffer [ ] , int offset , int len ) throws java . io . IOException { for ( int i = 0 ; i < len ; i ++ ) { int q = in . read ( ) ; if ( q == - 1 ) return ( ( i == 0 ) ? - 1 : i ) ; buffer [ i + offset ] = ( byte ) q ; } return len ; }
this method works around the bizarre semantics of bufferedinputstream ' s read method .
