public static void write(Object value, Writer out) throws IOException {
		if(out instanceof MediaWriter) {
			// Unwrap media writer and use encoder directly
			MediaWriter mediaWriter = (MediaWriter)out;
			write(
				value,
				mediaWriter.getEncoder(),
				mediaWriter.getOut()
			);
		} else {
			if(value instanceof String) {
				// If A is a string, then the result is A.
				out.write((String)value);
			} else if(value == null) {
				// Otherwise, if A is null, then the result is "".
				// Write nothing
			} else if(value instanceof Writable) {
				Writable writable = (Writable)value;
				if(writable.isFastToString()) {
					out.write(writable.toString());
				} else {
					// Avoid intermediate String from Writable
					writable.writeTo(unwrap(out));
				}
			} else if(value instanceof Node) {
				// Otherwise, if is a DOM node, serialize the output
				try {
					// Can use thread-local or pooled transformers if performance is ever an issue
					TransformerFactory transFactory = TransformerFactory.newInstance();
					Transformer transformer = transFactory.newTransformer();
					transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
					transformer.transform(
						new DOMSource((Node)value),
						new StreamResult(unwrap(out))
					);
				} catch(TransformerException e) {
					throw new IOException(e);
				}
			} else {
				// Otherwise, if A.toString() throws an exception, then raise an error
				// Otherwise, the result is A.toString();
				out.write(value.toString());
			}
		}
	}
public static void write ( Object value , Writer out ) throws IOException { if ( out instanceof MediaWriter ) { MediaWriter mediaWriter = ( MediaWriter ) out ; write ( value , mediaWriter . getEncoder ( ) , mediaWriter . getOut ( ) ) ; } else { if ( value instanceof String ) { out . write ( ( String ) value ) ; } else if ( value == null ) { } else if ( value instanceof Writable ) { Writable writable = ( Writable ) value ; if ( writable . isFastToString ( ) ) { out . write ( writable . toString ( ) ) ; } else { writable . writeTo ( unwrap ( out ) ) ; } } else if ( value instanceof Node ) { try { TransformerFactory transFactory = TransformerFactory . newInstance ( ) ; Transformer transformer = transFactory . newTransformer ( ) ; transformer . setOutputProperty ( OutputKeys . OMIT_XML_DECLARATION , "yes" ) ; transformer . transform ( new DOMSource ( ( Node ) value ) , new StreamResult ( unwrap ( out ) ) ) ; } catch ( TransformerException e ) { throw new IOException ( e ) ; } } else { out . write ( value . toString ( ) ) ; } } }
Coerces an object to a String representation, supporting streaming for specialized types.