Bug fix
1. Directly flush buffer when written bytes is less than threshold in spilling buffer.
2. Avoid the zero buffer array length in spilling buffer.