_bufferChunked=true;
    private void prepareBuffers() throws IOException    {        // if we are not flushing an existing chunk        if (!_bufferChunked)        {            // Refill buffer if possible            if (_content != null && _content.length() > 0 && _buffer != null && _buffer.space() > 0)            {                int len = _buffer.put(_content);                _content.skip(len);                if (_content.length() == 0)                     _content = null;            }            // Chunk buffer if need be            if (_contentLength == CHUNKED_CONTENT)            {                int size = _buffer == null ? 0 : _buffer.length();                if (size > 0)                {                    // Prepare a chunk!                    _bufferChunked = true;                    // Did we leave space at the start of the buffer.                    if (_buffer.getIndex() == CHUNK_SPACE)                    {                        // Oh yes, goodie! let's use it then!                        _buffer.poke(_buffer.getIndex() - 2, CRLF, 0, 2);                        _buffer.setGetIndex(_buffer.getIndex() - 2);                        BufferUtil.prependHexInt(_buffer, size);                        if (_needCRLF)                        {                            _buffer.poke(_buffer.getIndex() - 2, CRLF, 0, 2);                            _buffer.setGetIndex(_buffer.getIndex() - 2);                            _needCRLF = false;                        }                    }                    else                    {                        // No space so lets use the header buffer.                        if (_needCRLF)                        {                            if (_header.length() > 0) throw new IllegalStateException("EOC");                            _header.put(CRLF);                            _needCRLF = false;                        }                        BufferUtil.putHexInt(_header, size);                        _header.put(CRLF);                    }                    // Add end chunk trailer.                    if (_buffer.space() >= 2)                        _buffer.put(CRLF);                    else                        _needCRLF = true;                }                // If we need EOC and everything written                if (_needEOC && (_content == null || _content.length() == 0))                {                    if (_needCRLF)                    {                        if (_buffer == null && _header.space() >= 2)                        {                            _header.put(CRLF);                            _needCRLF = false;                        }                        else if (_buffer.space() >= 2)                        {                            _buffer.put(CRLF);                            _needCRLF = false;                        }                    }                    if (!_needCRLF && _needEOC)                    {                        if (_buffer == null && _header.space() >= LAST_CHUNK.length)                        {                            _header.put(LAST_CHUNK);                            _needEOC = false;                        }                        else if (_buffer.space() >= LAST_CHUNK.length)                        {                            _buffer.put(LAST_CHUNK);                            _needEOC = false;                        }                    }                }            }        }        if (_content != null && _content.length() == 0)             _content = null;    }