### Question:
OutputStreamHandler extends WriterHandler { public void setWriter(final Writer writer) { synchronized (outputLock) { super.setWriter(writer); final OutputStream oldStream = this.outputStream; outputStream = null; safeFlush(oldStream); safeClose(oldStream); } } OutputStreamHandler();  OutputStreamHandler(final Formatter formatter);  OutputStreamHandler(final OutputStream outputStream, final Formatter formatter); Charset getCharset(); void setWriter(final Writer writer); void setOutputStream(final OutputStream outputStream);  }### Answer:
@Test public void testSetEncodingOnOutputStream() throws Exception { handler = new ConsoleHandler(Target.CONSOLE, NO_FORMATTER); handler.setErrorManager(AssertingErrorManager.of()); handler.setWriter(out); handler.setEncoding("UTF-8"); assertThat(handler.getEncoding(), is("UTF-8")); handler.publish(new ExtLogRecord(Level.INFO, "Hello World", getClass().getName())); assertThat(out.toString(), is("Hello World")); }
@Test public void testSetNullEncodingOnOutputStream() throws Exception { handler = new OutputStreamHandler(NO_FORMATTER); handler.setErrorManager(AssertingErrorManager.of()); handler.setWriter(out); handler.setEncoding(null); handler.publish(new ExtLogRecord(Level.INFO, "Hello World", getClass().getName())); assertThat(out.toString(), is("Hello World")); }