code: public static void write(String str, final OutputStream outputStream, Charset charset)
        throws IOException {
      new ByteSink() {
        @Override
        public OutputStream openStream() {
          return outputStream;
        }
      }.asCharSink(charset).write(str);
    }
docs: Writes the specified string to stream with buffering and closes the stream.
  
  @param str String to write.
  @param outputStream Stream to write to.
  @param charset The charset to write in.
  @throws IOException If there is an exception while writing.