code: public int read(byte[] buf, int off, int len) throws IOException {
      if (buf.length < (len + off - 1)) {
        throw new IOException("The input buffer is too small: " + len
                + " bytes requested starting at offset " + off + " while the buffer " + " is only "
                + buf.length + " bytes long.");
      }
  
      // This could of course be optimized
      int i;
      for (i = 0; i < len; i++) {
        int x = read();
        if (x == -1 && i == 0) { // an immediate -1 returns -1
          return -1;
        } else if (x == -1) { // a later -1 returns the chars read so far
          break;
        }
        buf[off + i] = (byte) x;
      }
      return i;
    }
docs: *
  Reads decoded data into an array of bytes and returns the actual number of bytes read, or -1 if
  end of stream was reached.
  
  @param buf the buffer into which the data is read
  @param off the start offset of the data
  @param len the maximum number of bytes to read
  @return the actual number of bytes read, or -1 if the end of the input stream is reached
  @exception IOException if an I/O error occurs