Use StringIO for pure python legacy batch inserts.

This reduces memory fragmentation when encoding large
batches of documents for insert. Testing shows improvements
in memory usage in pure python and reduced GC overhead in
Jython with no reduction in performance.