if (!buffer.isImmutable()) buffer.setGetIndex(bbuf.position());
if (len>0) buffer.skip(len);
    public int flush(Buffer buffer) throws IOException    {        Buffer buf = buffer.buffer();        int len=0;        if (buf instanceof NIOBuffer)        {            NIOBuffer nbuf = (NIOBuffer)buf;            ByteBuffer bbuf=nbuf.getByteBuffer();            // TODO synchronize or duplicate?            synchronized(nbuf)            {                try                {                    bbuf.position(buffer.getIndex());                    bbuf.limit(buffer.putIndex());                    len=_channel.write(bbuf);                }                finally                {                    if (!buffer.isImmutable())                        buffer.setGetIndex(bbuf.position());                    bbuf.position(0);                    bbuf.limit(bbuf.capacity());                }            }        }        else if (buffer.array()!=null)        {            ByteBuffer b = ByteBuffer.wrap(buffer.array(), buffer.getIndex(), buffer.length());            len=_channel.write(b);            if (!buffer.isImmutable())                buffer.setGetIndex(b.position());        }        else        {            throw new IOException("Not Implemented");        }                return len;    }