if (buffer != null) {
if (this.length + len > MAX_BUFFER_SIZE) {
// threshold for keeping data in memory exceeded;
// create temp file and spool buffer contents
TransientFileFactory fileFactory = TransientFileFactory.getInstance();
tmpFile = fileFactory.createTransientFile("txt", null, null);
BufferedOutputStream fout = new BufferedOutputStream(new FileOutputStream(tmpFile));
writer = new OutputStreamWriter(fout, "UTF-8");
writer.write(buffer.toString());
writer.write(chars, start, len);
// reset the in-memory buffer