private void flush() throws IOException {
ByteArrayOutputStream buf = getBuffer();
if (buf.size() == 0) {
return; // no data to flush
}
buf.writeTo(fp); // write data to file
buf.reset(); // erase all data in buf
}
void close() throws IOException {
// close should have been called after all pending transactions