code: public int readAll(char []buf, int offset, int length) throws IOException
    {
      int readLength = 0;
  
      while (length > 0) {
        int sublen = read(buf, offset, length);
  
        if (sublen <= 0) {
          return readLength > 0 ? readLength : -1;
        }
  
        offset += sublen;
        readLength += sublen;
        length -= sublen;
      }
  
      return readLength;
    }
docs: Reads into a character buffer from the stream.  <code>length</code>
  characters will always be read until the end of file is reached.
  
  @param buf character buffer to fill
  @param offset starting offset into the character buffer
  @param length maximum number of characters to read
  @return number of characters read or -1 on end of file.