Buffered Writer
Asked at Databricks
Reported by the problem's creator, not verified
You are implementing BufferedWriter, a log writer that collects lines in memory and moves them to a file in batches. Each line has the form thread:message. The file only ever receives lines from the buffer, in the order they were written. Each test creates one BufferedWriter(capacity) and calls its methods in sequence; every return value is checked.
Examples
Example 1
Input: init =
[2], operations =[["write",["t1","alpha"]],["write",["t2","beta"]],["write",["t1","gamma"]],["flush",[]],["write",["t3","delta"]],["close",[]]]Output:
[1,0,1,1,1,["t1:alpha","t2:beta","t1:gamma","t3:delta"]]Explanation: With capacity 2 the second write fills the buffer and flushes it automatically, so it returns 0. gamma is buffered, flush writes it and returns 1, delta is buffered, and close flushes it and returns the whole file in write order.