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

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