UnsyncPrintWriter extends PrintWriter { @Override public void flush() { if (_writer == null) { _hasError = true; } else { try { _writer.flush(); } catch (IOException ioException) { _hasError = true; } } } UnsyncPrintWriter(File file);  UnsyncPrintWriter(File file, String csn);  UnsyncPrintWriter(OutputStream outputStream);  UnsyncPrintWriter(String fileName);  UnsyncPrintWriter(String fileName, String csn);  UnsyncPrintWriter(Writer writer); @Override PrintWriter append(char c); @Override PrintWriter append(CharSequence charSequence); @Override PrintWriter append(CharSequence charSequence, int start, int end); @Override boolean checkError(); @Override void close(); @Override void flush(); @Override PrintWriter format(
		Locale locale, String format, Object... arguments); @Override PrintWriter format(String format, Object... arguments); @Override void print(boolean b); @Override void print(char c); @Override void print(char[] chars); @Override void print(double d); @Override void print(float f); @Override void print(int i); @Override void print(long l); @Override void print(Object object); @Override void print(String string); @Override PrintWriter printf(
		Locale locale, String format, Object... arguments); @Override PrintWriter printf(String format, Object... arguments); @Override void println(); @Override void println(boolean b); @Override void println(char c); @Override void println(char[] chars); @Override void println(double d); @Override void println(float f); @Override void println(int i); @Override void println(long l); @Override void println(Object object); @Override void println(String string); void reset(Writer writer); @Override void write(char[] chars); @Override void write(char[] chars, int offset, int length); @Override void write(int c); @Override void write(String string); @Override void write(String string, int offset, int length);  }
@Test public void testFlush() { AtomicBoolean calledFlush = new AtomicBoolean(); UnsyncPrintWriter unsyncPrintWriter = new UnsyncPrintWriter( new StringWriter() { @Override public void flush() { calledFlush.set(true); } }); unsyncPrintWriter.flush(); Assert.assertTrue(calledFlush.get()); calledFlush.set(false); unsyncPrintWriter.close(); unsyncPrintWriter.flush(); Assert.assertFalse(calledFlush.get()); Assert.assertTrue(unsyncPrintWriter.checkError()); unsyncPrintWriter.reset(null); Assert.assertFalse(unsyncPrintWriter.checkError()); unsyncPrintWriter.reset( new Writer() { @Override public void close() { throw new UnsupportedOperationException(); } @Override public void flush() throws IOException { throw new IOException(); } @Override public void write(char[] cbuf, int off, int len) { throw new UnsupportedOperationException(); } }); unsyncPrintWriter.flush(); Assert.assertTrue(unsyncPrintWriter.checkError()); }