Problem Description
The existing File object:
- Is constructed with a file path (string as an argument).
- Has a single method called `Write`, which persists bytes directly to disk.
Example:
var f = new File("/tmp/my/file.txt");
f.Write(Encoding.UTF8.GetBytes("hello world"));
Write a wrapper class for the file object which allows us to buffer the writes in-memory.
The wrapper class, `BufferedFile`, is initialized with a `File` object and a buffer size.
It has two methods: `Write` and `Flush`.
- The data should be flushed to disk when the buffer is full,
- or on demand with a method called `Flush`.
All bytes must be stored in the buffer first before being written to disk.
The buffer cannot use more memory than the max bytes allowed.
Example usage:
var f = new File("/tmp/my/file.txt");
int bufSize = 1000;
var b = new BufferedFile(f, bufSize);
b.Write(Encoding.UTF8.GetBytes("hello world"));
b.Flush();
Hints
No hints available for this question.