void () { if (fileState == null) return; synchronized (fileState) { if (fileState.finished) return; try { if (!fileState.openBracketWritten) { fileState.writer.write("[\n"); fileState.openBracketWritten = true; } while (true) { Span span = spans.pollLast(); if (span == null) break; fileState.writer.write(serialize(span, true)); fileState.writer.write(serialize(span, false)); } if (shouldFinish) { fileState.writer.write("]"); } fileState.writer.flush(); } catch (IOException e) { myExceptionHandler.accept(e); } } }