I was helping a friend to write some Java code, who doesn\'t know a lot about Java. So I wrote him some helper functions to easily get things done that are a little quirky i
Let's look at this from the caller's point of view.
The caller has an OutputStream of some sort, and calls a method called write(). After the call completes, the caller discovers that the stream has been closed.
In my view, your write() method simply should not call printer.close(). The latter closes the stream provided by the caller and is probably not what the caller expects.
If you need to flush the stream, you could use flush().