if (len>0&&_buffer.space()==0) { len--; _buffer.setPutIndex(_buffer.putIndex()-1);
if(len > 0 && _buffer.space() == 0) { len--; _buffer.setPutIndex(_buffer.putIndex() - 1); } _content.skip(len);  if(_content.length() == 0) _content = null;  if(_buffer.length() == 0) { _content = null; } }   if(_buffer != null) {  int payloadSize = _buffer.length();       if(payloadSize > 0) { _bufferPrepared = true;  _buffer.put((byte) 0); int put = _buffer.putIndex(); _buffer.setGetIndex(0); _buffer.setPutIndex(0); _buffer.put((byte) 'A'); _buffer.put((byte) 'B'); addInt(payloadSize + 4); _buffer.put((byte) 3); addInt(payloadSize); _buffer.setPutIndex(put); } }                           if(!_needMore && _needEOC) { if(_buffer == null && _header.space() >= AJP13_END_RESPONSE.length) { _hasSentEOC = true; _header.put(AJP13_END_RESPONSE); _needEOC = false; } else if(_buffer != null && _buffer.space() >= AJP13_END_RESPONSE.length) {   _hasSentEOC = true; _buffer.put(AJP13_END_RESPONSE); _needEOC = false; _bufferPrepared = true; } }
    private void prepareBuffers()    {        if (!_bufferPrepared)        {            // Refill buffer if possible            if (_content!=null&&_content.length()>0&&_buffer!=null&&_buffer.space()>0)            {                int len=_buffer.put(_content);                // Make sure there is space for a trailing null                if (len>0&&_buffer.space()==0)                {                    len--;                    _buffer.setPutIndex(_buffer.putIndex()-1);                }                _content.skip(len);                if (_content.length()==0)                    _content=null;                if (_buffer.length()==0)                {                    _content=null;                }            }            // add header if needed            if (_buffer!=null)            {                int payloadSize=_buffer.length();                // 4 bytes for the ajp header                // 1 byte for response type                // 2 bytes for the response size                // 1 byte because we count from zero??                if (payloadSize>0)                {                    _bufferPrepared=true;                    _buffer.put((byte)0);                    int put=_buffer.putIndex();                    _buffer.setGetIndex(0);                    _buffer.setPutIndex(0);                    _buffer.put((byte)'A');                    _buffer.put((byte)'B');                    addInt(payloadSize+4);                    _buffer.put((byte)3);                    addInt(payloadSize);                    _buffer.setPutIndex(put);                }            }            if (_needMore)            {                                    if (_header==null)                    _header=_buffers.getBuffer(_headerBufferSize);                                if (_buffer==null&&_header!=null && _header.space()>=AJP13_MORE_CONTENT.length)                {                        if(!_hasSentEOC)                                _header.put(AJP13_MORE_CONTENT);                    _needMore=false;                }                else if (_buffer!=null && _buffer.space()>=AJP13_MORE_CONTENT.length)                {                    // send closing packet if all contents                    // are added                if(!_hasSentEOC)                        _buffer.put(AJP13_MORE_CONTENT);                    _needMore=false;                    _bufferPrepared=true;                }            }            if (_needEOC)            {                if (_buffer==null&&_header.space()>=AJP13_END_RESPONSE.length)                {                    _hasSentEOC = true;                    _header.put(AJP13_END_RESPONSE);                    _needEOC=false;                }                else if (_buffer!=null&&_buffer.space()>=AJP13_END_RESPONSE.length)                {                    // send closing packet if all contents                    // are added                    _hasSentEOC = true;                    _buffer.put(AJP13_END_RESPONSE);                    _needEOC=false;                    _bufferPrepared=true;                }            }        }    }