based on commons buffered writer