/** * Switches the underlying output stream from a memory based stream to one * that is backed by disk. This is the point at which we realise that too * much data is being written to keep in memory, so we elect to switch to * disk-based storage. * * @throws IOException if an error occurs. */ @Override protected void thresholdReached() throws IOException { if (prefix != null) { outputFile = File.createTempFile(prefix, suffix, directory); } FileUtils.forceMkdirParent(outputFile); final FileOutputStream fos = new FileOutputStream(outputFile); try { memoryOutputStream.writeTo(fos); } catch (final IOException e){ fos.close(); throw e; } currentOutputStream = fos; memoryOutputStream = null; }