code:     public int doRead(ByteChunk chunk, Request req) throws IOException {
          checkError();
  
          if (endChunk) {
              return -1;
          }
  
          if(needCRLFParse) {
              needCRLFParse = false;
              parseCRLF(false);
          }
  
          if (remaining <= 0) {
              if (!parseChunkHeader()) {
                  throwIOException(sm.getString("chunkedInputFilter.invalidHeader"));
              }
              if (endChunk) {
                  parseEndChunk();
                  return -1;
              }
          }
  
          int result = 0;
  
          if (pos >= lastValid) {
              if (readBytes() < 0) {
                  throwIOException(sm.getString("chunkedInputFilter.eos"));
              }
          }
  
          if (remaining > (lastValid - pos)) {
              result = lastValid - pos;
              remaining = remaining - result;
              chunk.setBytes(buf, pos, result);
              pos = lastValid;
          } else {
              result = remaining;
              chunk.setBytes(buf, pos, remaining);
              pos = pos + remaining;
              remaining = 0;
              //we need a CRLF
              if ((pos+1) >= lastValid) {
                  //if we call parseCRLF we overrun the buffer here
                  //so we defer it to the next call BZ 11117
                  needCRLFParse = true;
              } else {
                  parseCRLF(false); //parse the CRLF immediately
              }
          }
  
          return result;
      }
  
  
      // ---------------------------------------------------- InputFilter Methods
  
      /**
       * Read the content length from the request.
       */
      @Override
  