### Question:
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; } DeferredFileOutputStream(final int threshold, final File outputFile);  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); boolean isInMemory(); byte[] getData(); File getFile(); @Override void close(); void writeTo(final OutputStream out);  }### Answer:
@Test public void testThresholdReached() { final File testFile = new File("testThresholdReached.dat"); testFile.delete(); final DeferredFileOutputStream dfos = new DeferredFileOutputStream(testBytes.length / 2, testFile); final int chunkSize = testBytes.length / 3; try { dfos.write(testBytes, 0, chunkSize); dfos.write(testBytes, chunkSize, chunkSize); dfos.write(testBytes, chunkSize * 2, testBytes.length - chunkSize * 2); dfos.close(); } catch (final IOException e) { fail("Unexpected IOException"); } assertFalse(dfos.isInMemory()); assertNull(dfos.getData()); verifyResultFile(testFile); testFile.delete(); }