code: public int read() throws IOException {
      if (totalRead >= totalExpected) {
        return -1;
      }
  
      int result = in.read();
      if (result != -1) {
        totalRead++;
      }
      return result;
    }
docs: Implement length limitation on top of the <code>read</code> method of
  the wrapped <code>ServletInputStream</code>.
  
  @return     the next byte of data, or <code>-1</code> if the end of the
  stream is reached.
  @exception  IOException  if an I/O error occurs.