UnsyncBufferedWriter extends Writer { @Override public void flush() throws IOException { if (_writer == null) { throw new IOException("Writer is null"); } if (_count > 0) { _writer.write(_buffer, 0, _count); _count = 0; } _writer.flush(); } UnsyncBufferedWriter(Writer writer);  UnsyncBufferedWriter(Writer writer, int size); @Override void close(); @Override void flush(); void newLine(); @Override void write(char[] chars, int offset, int length); @Override void write(int c); @Override void write(String string, int offset, int length);  }
@Test public void testFlush() throws IOException { StringWriter stringWriter = new StringWriter(); UnsyncBufferedWriter unsyncBufferedWriter = new UnsyncBufferedWriter( stringWriter, 4); unsyncBufferedWriter.write("test"); unsyncBufferedWriter.flush(); Assert.assertEquals("test", stringWriter.toString()); unsyncBufferedWriter.flush(); Assert.assertEquals("test", stringWriter.toString()); }