code: public void writeTo(Writer target, boolean flushTarget, boolean emptyAfter) throws IOException {
          if (target instanceof GrailsWrappedWriter) {
              GrailsWrappedWriter wrappedWriter = ((GrailsWrappedWriter)target);
              if (wrappedWriter.isAllowUnwrappingOut()) {
                  target = wrappedWriter.unwrap();
              }
          }
          if (target == writer) {
              throw new IllegalArgumentException("Cannot write buffer to itself.");
          }
          if (!emptyAfter && target instanceof StreamCharBufferWriter) {
              ((StreamCharBufferWriter)target).write(this, null);
              return;
          } else if (writeToEncodedAppender(this, target, writer.getEncodedAppender(), true)) {
              if (emptyAfter) {
                  emptyAfterReading();
              }
              if (flushTarget) {
                  target.flush();
              }
              return;
          }
          writeToImpl(target, flushTarget, emptyAfter);
      }
docs: Writes the buffer content to a target java.io.Writer
  
  @param target Writer
  @param flushTarget calls target.flush() before finishing
  @param emptyAfter empties the buffer if true
  @throws IOException