WriterOutputStream extends AppendableOutputStream { @Override public void flush() throws IOException { super.flush(); writer.flush(); } WriterOutputStream(final Writer writer, final CharsetDecoder decoder);  WriterOutputStream(final Writer writer, final CharsetDecoder decoder, final int bufferSize);  WriterOutputStream(final Writer writer, final Charset charset, final int bufferSize);  WriterOutputStream(final Writer writer, final Charset charset);  WriterOutputStream(final Writer writer, final String charsetName, final int bufferSize);  WriterOutputStream(final Writer writer, final String charsetName); @Override void flush(); @Override @DischargesObligation void close(); @Override String toString();  }
@Test public void testFlush() throws IOException { final StringWriter writer = new StringWriter(); final WriterOutputStream out = new WriterOutputStream(writer, "us-ascii", 1024); out.write("abc".getBytes(StandardCharsets.US_ASCII)); assertEquals(0, writer.getBuffer().length()); out.flush(); assertEquals("abc", writer.toString()); out.close(); }