### Question:
HprofCruncher { public static void crunch(@Nonnull HprofSource source, @Nonnull OutputStream out, @Nullable Config config) throws IOException, TimeoutException { if (config == null) { config = new Config.Builder().build(); } Stats.setEnabled(config.collectStats); Stats.increment(Stats.Type.TOTAL, Stats.Variant.HPROF, source.getDataSize()); final long start = System.currentTimeMillis(); final long limit = config.timeLimit != Config.NO_TIME_LIMIT ? start + config.timeLimit : Long.MAX_VALUE; CountingOutputStream cOut = new CountingOutputStream(out); if (config.collectStats) { out = cOut; } CrunchProcessor processor = new CrunchProcessor(out, config.preservedClasses, true); InputStream in = new BufferedInputStream(source.open()); try { HprofReader reader = new HprofReader(in, processor); while (reader.hasNext()) { reader.next(); checkTimeLimit(limit); iterationSleep(config); } processor.startSecondPass(); } finally { in.close(); } in = new BufferedInputStream(source.open()); try { HprofReader reader = new HprofReader(in, processor); while (reader.hasNext()) { reader.next(); checkTimeLimit(limit); iterationSleep(config); } processor.finishAndWriteOutput(); } finally { in.close(); } Stats.increment(Stats.Type.TOTAL, Stats.Variant.BMD, cOut.getCount()); Stats.printStats(); }  static void crunch(@Nonnull HprofSource source, @Nonnull OutputStream out, @Nullable Config config); static void main(String[] args);  }### Answer:
@Test public void testCrunch() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); HprofSource source = new HprofFileSource(new File("../test_files/crunch_test_in.hprof")); HprofCruncher.Config config = new HprofCruncher.Config.Builder().stats(true).build(); HprofCruncher.crunch(source, out, config); verify(new FileInputStream("../test_files/crunch_test_out.bmd"), new ByteArrayInputStream(out.toByteArray())); }