### Question:
LogBufferWriter implements Flushable, Closeable { public LogBufferWriter(String logBufferBaseDir, long maxFileSize, Runnable cleaner) throws IOException { File baseDir = new File(logBufferBaseDir); Files.createDirectories(baseDir.toPath()); this.locationFactory = new LocalLocationFactory(baseDir); this.maxFileSizeInBytes = maxFileSize; this.cleaner = cleaner; this.cleanerFuture = CompletableFuture.completedFuture(0); this.executorService = Executors.newSingleThreadExecutor(Threads.createDaemonThreadFactory("log-buffer-cleaner")); this.logEventSerializer = new LoggingEventSerializer(); this.currFileId = getNextFileId(baseDir); this.currOutputStream = new BufferedOutputStream(locationFactory.create(getFileName(currFileId)).getOutputStream()); } LogBufferWriter(String logBufferBaseDir, long maxFileSize, Runnable cleaner); Iterable<LogBufferEvent> write(Iterator<byte[]> events); @Override void flush(); @Override void close();  }### Answer:
@Test public void testLogBufferWriter() throws Exception { String absolutePath = TMP_FOLDER.newFolder().getAbsolutePath(); LogBufferWriter writer = new LogBufferWriter(absolutePath, 100000, () -> { }); ImmutableList<byte[]> events = getLoggingEvents(); Iterator<LogBufferEvent> writtenEvents = writer.write(events.iterator()).iterator(); writer.close(); int i = 0; int startPos = 0; while (writtenEvents.hasNext()) { LogBufferEvent bufferEvent = writtenEvents.next(); Assert.assertEquals(String.valueOf(i++), bufferEvent.getLogEvent().getMessage()); Assert.assertEquals(bufferEvent.getOffset().getFilePos(), startPos); startPos = startPos + Bytes.SIZEOF_INT + serializer.toBytes(bufferEvent.getLogEvent()).length; } try (DataInputStream dis = new DataInputStream(new FileInputStream(absolutePath + "/0.buf"))) { for (byte[] eventBytes : events) { ILoggingEvent event = serializer.fromBytes(ByteBuffer.wrap(eventBytes)); Assert.assertEquals(event.getMessage(), getEvent(dis, serializer.toBytes(event).length).getMessage()); } } }