PrefixPrintWriter extends PrintWriter { public PrefixPrintWriter(Writer out, String prefix) { super(out); this.prefix = prefix; } PrefixPrintWriter(Writer out, String prefix);  PrefixPrintWriter(Writer out, String prefix, boolean autoFlush);  PrefixPrintWriter(OutputStream out, String prefix);  PrefixPrintWriter(OutputStream out, String prefix, boolean autoFlush);  PrefixPrintWriter(String fileName, String prefix);  PrefixPrintWriter(String fileName, String prefix, String csn);  PrefixPrintWriter(File file, String prefix);  PrefixPrintWriter(File file, String prefix, String csn); @Override void println(); @Override void println(boolean x); @Override void println(char x); @Override void println(int x); @Override void println(long x); @Override void println(float x); @Override void println(double x); @Override void println(char[] x); @Override void println(String x); @Override void println(Object x); @Override void write(int c); @Override void write(char[] buf, int off, int len); @Override void write(char[] buf); @Override void write(String s, int off, int len); @Override void write(String s); @Override PrintWriter printf(String format, Object... args); @Override PrintWriter printf(Locale l, String format, Object... args); @Override PrintWriter format(String format, Object... args); @Override PrintWriter format(Locale l, String format, Object... args);  }
@Test public void testPrefixPrintWriter() { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); String nl = System.getProperty("line.separator"); String expectedResult = "AAABBB1234" + nl + "AAABBB1234" + nl + "AAABBB1234" + nl; PrefixPrintWriter ppw = new PrefixPrintWriter(new PrefixPrintWriter(pw, "AAA"), "BBB"); for (int i = 0; i < 3; i++) { ppw.print("1"); ppw.print("2"); ppw.print("3"); ppw.println("4"); } ppw.flush(); String output = sw.toString(); System.out.println(output); Assert.assertEquals(expectedResult, output); }