### Question:
SimpleFlamdexDocWriter implements FlamdexDocWriter { @Override public void close() throws IOException { flush(); long numDocs = 0; final List<FlamdexReader> allReaders = Lists.newArrayList(); for (final File file : Iterables.concat(Lists.reverse(segmentsOnDisk.subList(1, segmentsOnDisk.size())))) { final SimpleFlamdexReader reader = SimpleFlamdexReader.open(file.getAbsolutePath(), new SimpleFlamdexReader.Config().setWriteBTreesIfNotExisting(false)); allReaders.add(reader); numDocs += reader.getNumDocs(); } for (final File file : segmentsOnDisk.get(0)) { final FlamdexReader reader = MemoryFlamdex.streamer(new BufferedFileDataInputStream(file, ByteOrder.nativeOrder(), 65536)); allReaders.add(reader); numDocs += reader.getNumDocs(); } final FlamdexWriter w = new SimpleFlamdexWriter(outputDirectory, numDocs, true, true); SimpleFlamdexWriter.merge(allReaders, w); w.close(); for (final FlamdexReader reader : allReaders) { reader.close(); } for (final File file : Iterables.concat(segmentsOnDisk)) { rmrf(file); } } SimpleFlamdexDocWriter(String outputDirectory, Config config); @Override void addDocument(FlamdexDocument doc); @Override void close();  }### Answer:
@Test public void testBufferedOnly() throws IOException { final SimpleFlamdexDocWriter.Config config = new SimpleFlamdexDocWriter.Config().setDocBufferSize(999999999).setMergeFactor(999999999); writeFlamdex(tempDir, config); final FlamdexReader r = SimpleFlamdexReader.open(tempDir); assertTrue(r.getIntFields().size() == 2); assertTrue(r.getIntFields().contains("if1")); assertTrue(r.getIntFields().contains("if2")); assertTrue(r.getStringFields().size() == 2); assertTrue(r.getStringFields().contains("sf1")); assertTrue(r.getStringFields().contains("sf2")); DocIdStream dis = r.getDocIdStream(); int[] docIdBuffer = new int[64]; IntTermIterator iter = r.getIntTermIterator("if1"); assertTrue(iter.next()); assertEquals(0, iter.term()); assertEquals(2, iter.docFreq()); dis.reset(iter); assertEquals(2, dis.fillDocIdBuffer(docIdBuffer)); assertEquals(Ints.asList(0, 3), Ints.asList(docIdBuffer).subList(0, 2)); assertTrue(iter.next()); assertEquals(5, iter.term()); assertEquals(1, iter.docFreq()); dis.reset(iter); assertEquals(1, dis.fillDocIdBuffer(docIdBuffer)); assertEquals(Ints.asList(0), Ints.asList(docIdBuffer).subList(0, 1)); iter.close(); }
@Test public void testEmpty() throws IOException { new SimpleFlamdexDocWriter(tempDir, new SimpleFlamdexDocWriter.Config()).close(); FlamdexReader r = SimpleFlamdexReader.open(tempDir); assertEquals(0, r.getNumDocs()); }