class DeferredFileOutputStream extends ThresholdingOutputStream {

    @Override
    protected void thresholdReached() throws IOException
    {
        if (prefix != null) {
            outputFile = File.createTempFile(prefix, suffix, directory);
        }
        final FileOutputStream fos = new FileOutputStream(outputFile);
        try {
            memoryOutputStream.writeTo(fos);
        } catch (IOException e){
            fos.close();
            throw e;
        }
        currentOutputStream = fos;
        memoryOutputStream = null;
    }

    public  DeferredFileOutputStream(final int threshold, final File outputFile);
    public  DeferredFileOutputStream(final int threshold, final String prefix, final String suffix, final File directory);
    private  DeferredFileOutputStream(final int threshold, final File outputFile, final String prefix,
                                     final String suffix, final File directory);

}