code: public static PrintWriter encodedOutputStreamPrintWriter(OutputStream stream,
                       String encoding, boolean autoFlush) throws IOException {
      // PrintWriter doesn't allow encoding to be null; or to have charset and flush
      if (encoding == null) {
        return new PrintWriter(stream, autoFlush);
      } else {
        return new PrintWriter(new OutputStreamWriter(stream, encoding), autoFlush);
      }
    }
docs: Create a Reader with an explicit encoding around an InputStream.
  This static method will treat null as meaning to use the platform default,
  unlike the Java library methods that disallow a null encoding.
  
  @param stream An InputStream
  @param encoding A charset encoding
  @return A Reader
  @throws IOException If any IO problem