_buffer.clear();    _buffer.setPutIndex(7); _buffer.setGetIndex(7);      if (_content!=null&&_content.length()<_buffer.space()&&_state!=STATE_FLUSHING) {  _buffer.put(_content); _content.clear(); _content=null; break Flushing; }
if(!_needMore && _needEOC && _buffer != null) { _hasSentEOC = true; _buffer.put(AJP13_END_RESPONSE); } _needEOC = false; return 0;
    public long flush() throws IOException    {        try        {            if (!_needMore && _state==STATE_HEADER)                throw new IllegalStateException("State==HEADER");            prepareBuffers();            if (_endp==null)            {                if (_needMore && _buffer != null)                {                        if(!_hasSentEOC)                                _buffer.put(AJP13_MORE_CONTENT);                }                if (_needEOC&&_buffer!=null)                {                     _hasSentEOC = true;                    _buffer.put(AJP13_END_RESPONSE);                }                _needEOC=false;                return 0;            }            // Keep flushing while there is something to flush            // (except break below)            int total=0;            long last_len=-1;            Flushing: while (true)            {                int len=-1;                int to_flush=((_header!=null&&_header.length()>0)?4:0)|((_buffer!=null&&_buffer.length()>0)?2:0);                switch (to_flush)                {                    case 7:                        throw new IllegalStateException(); // should                        // never                        // happen!                    case 6:                        len=_endp.flush(_header,_buffer,null);                        break;                    case 5:                        throw new IllegalStateException(); // should                        // never                        // happen!                    case 4:                        len=_endp.flush(_header);                        break;                    case 3:                        throw new IllegalStateException(); // should                        // never                        // happen!                    case 2:                        len=_endp.flush(_buffer);                        break;                    case 1:                        throw new IllegalStateException(); // should                        // never                        // happen!                    case 0:                    {                        // Nothing more we can write now.                        if (_header!=null)                            _header.clear();                        _bufferPrepared=false;                        if (_buffer!=null)                        {                            _buffer.clear();                            // reserve some space for the                            // header                            _buffer.setPutIndex(7);                            _buffer.setGetIndex(7);                            // Special case handling for                            // small left over buffer from                            // an addContent that caused a                            // buffer flush.                            if (_content!=null&&_content.length()<_buffer.space()&&_state!=STATE_FLUSHING)                            {                                _buffer.put(_content);                                _content.clear();                                _content=null;                                break Flushing;                            }                        }                        // Are we completely finished for now?                        if (!_needMore && !_needEOC && (_content==null||_content.length()==0))                        {                            if (_state==STATE_FLUSHING)                                _state=STATE_END;                            if (_state==STATE_END&&_close)                                _endp.close();                            break Flushing;                        }                        // Try to prepare more to write.                        prepareBuffers();                    }                }                // If we failed to flush anything twice in a row                // break                if (len<=0)                {                    if (last_len<=0)                        break Flushing;                    break;                }                last_len=len;                total+=len;            }            return total;        }        catch (IOException e)        {            Log.ignore(e);            throw (e instanceof EofException)?e:new EofException(e);        }    }