Creates an output stream from the specified document.

@param doc
document input
@return output stream
481176
public static StreamingOutput createStream(final Document doc) {
        return new StreamingOutput() {

            @Override
            public void write(final OutputStream output) {
                synchronized (output) {
                    final DOMSource domSource = new DOMSource(doc);
                    final StreamResult streamResult = new StreamResult(output);
                    Transformer transformer;
                    try {
                        transformer = TransformerFactory.newInstance().newTransformer();
                        transformer.transform(domSource, streamResult);
                    } catch (final TransformerException exc) {
                        exc.printStackTrace();
                        throw new JaxRxException(exc);
                    }

                }
            }
        };
    }
635569
public Document doc() throws IOException {
		// if the stream has already been read, use the text format
		InputSource is;
		if (document == null) {
			if (text == null) {
				is = new InputSource(inputStream);
				is.setEncoding(getCharSet().name());
			} else {
				is = new InputSource(new StringReader(text));
			}
			try {
				document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);
			} catch (SAXException e) {
				e.printStackTrace();
			} catch (ParserConfigurationException e) {
				e.printStackTrace();
			}
			inputStream.close();
		}
		return document;
	}
1163778
public static void printDocument(Node _docOrNode, OutputStream _outStream) throws IOException {
        if (_docOrNode == null || _outStream == null) {
            throw new IOException("Cannot print (on) 'null' object");
        }

        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer transformer;
        try {
            transformer = tf.newTransformer();
            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
            transformer.setOutputProperty(OutputKeys.METHOD, "xml");
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
            transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");

            transformer.transform(new DOMSource(_docOrNode),
                 new StreamResult(new OutputStreamWriter(_outStream, "UTF-8")));
        } catch (UnsupportedEncodingException | TransformerException _ex) {
            throw new IOException("Could not print Document or Node.",_ex);
        }

    }
1339488
public synchronized OutputStream getOutputStream(int stream) {
    if (!output.containsKey(stream)) {
      output.put(stream, new WebSocketOutputStream(stream));
    }
    return output.get(stream);
  }
509128
public static ObjectStream<DocSample> getDocumentStream(
      final String inputData, String clearFeatures) throws IOException {
    final ObjectStream<String> docStream = IOUtils
        .readFileIntoMarkableStreamFactory(inputData);
    ObjectStream<DocSample> sampleStream = new DocSampleStream(clearFeatures,
        docStream);
    return sampleStream;
  }
259277
@Override
    public String stringify(Document document) {
        try {
            StringWriter sw = new StringWriter();
            TransformerFactory tf = TransformerFactory.newInstance();
            Transformer transformer = tf.newTransformer();
            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
            transformer.setOutputProperty(OutputKeys.METHOD, "xml");
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");

            transformer.transform(new DOMSource(document), new StreamResult(sw));
            return sw.toString();
        } catch (TransformerException e) {
            throw new RuntimeException(e);
        }
    }
69620
public <A extends Appendable> A document(A output) throws IOException {
        StringBuilder line = new StringBuilder();
        for (Field field: Beans.getKnownInstanceFields(_prototype)) {
            description d = field.getAnnotation(description.class);
            if (d == null) continue;

            placeholder p = field.getAnnotation(placeholder.class);
            String n = Strings.splitCamelCase(field.getName(), "-").toLowerCase();
            char key = getShortOptionKey(field);
            if ((field.getType() == Boolean.class || field.getType() == Boolean.TYPE) && _booleans.containsKey(key)) {
                line.append("  -").append(key).append(", --").append(n);
            } else {
                line.append("  --").append(n).append('=').append(p != null ? p.value() : "value");
            }
                if (line.length() < 16) {
                    for (int i = line.length(); i < 16; ++i) line.append(' ');
                    line.append(d.value());
                } else {
                    line.append("\n\t\t").append(d.value());
                }
            output.append(line.toString()).append('\n');
            line.setLength(0);
        }

        return output;
    }
1332188
public static byte[] getDocumentToByteArray(Document dom) {
        try {
            TransformerFactory tFactory = TransformerFactory.newInstance();

            Transformer transformer = tFactory.newTransformer();
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            transformer
                    .setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
            transformer.setOutputProperty(OutputKeys.METHOD, "html");
            // TODO should be fixed to read doctype declaration
            transformer
                    .setOutputProperty(
                            OutputKeys.DOCTYPE_PUBLIC,
                            "-//W3C//DTD XHTML 1.0 Strict//EN\" "
                                    + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd");

            DOMSource source = new DOMSource(dom);

            ByteArrayOutputStream out = new ByteArrayOutputStream();
            Result result = new StreamResult(out);
            transformer.transform(source, result);

            return out.toByteArray();
        } catch (TransformerException e) {
            LOGGER.error("Error while converting the document to a byte array",
                    e);
        }
        return null;

    }
1312795
public static XPathUtils newXPath(final Document doc) {
        final XPathFactory xpfactory = XPathFactory.newInstance();
        final XPath xPath = xpfactory.newXPath();
        return new XPathUtils(xPath, doc);
    }
408611
public static void serializeXMLDocument (Document doc, Writer output) throws TransformerException {
        // serialize XML document using identity transformation
        Transformer trans = TransformerFactory.newInstance().newTransformer();
        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(output);
        trans.transform(source, result);
    }
1031441
public static BsonDocument copyOfDocument(final BsonDocument document) {
    final BsonDocument newDocument = new BsonDocument();
    for (final Map.Entry<String, BsonValue> kv : document.entrySet()) {
      newDocument.put(kv.getKey(), kv.getValue());
    }
    return newDocument;
  }
410619
public static DocFile createFileForOutput(Configuration configuration, DocPath path) {
        return DocFileFactory.getFactory(configuration).createFileForOutput(path);
    }
980488
private PrintStream createOutputStream() {
        if (outputLogFilename != null) {
            try {
                FileOutputStream fout = new FileOutputStream(outputLogFilename, false);
                BufferedOutputStream bos = new BufferedOutputStream(fout, 4096);
                // We are using a PrintStream for output to match System.out
                if (encoding != null) {
                    return new PrintStream(bos, false, encoding);
                } else {
                    return new PrintStream(bos, false);
                }
            } catch (IOException e) {
                throw new IllegalArgumentException(getLocalizedString("CWTRA0005E"));
            }
        }

        // No output filename specified.
        isSystemOut = true;
        if (encoding != null) {
            try {
                // Encode output before directing it into System.out
                return new PrintStream(System.out, false, encoding);
            } catch (UnsupportedEncodingException e) {
                // We already checked that encoding is supported
            }
        }
        return System.out;
    }
1163921
public DataOutputStream createDataOutputStream(FSDataOutputStream outputStream) throws IOException {
        if (codec != null) {
            return new FSDataOutputStream(codec.createOutputStream(outputStream), null);
        } else {
            return outputStream;
        }
    }
250308
public String docToString(Document node) throws S2SException {
        try {
            DOMSource domSource = new DOMSource(node);
            StringWriter writer = new StringWriter();
            StreamResult result = new StreamResult(writer);
            TransformerFactory tf = TransformerFactory.newInstance();
            Transformer transformer = tf.newTransformer();
            transformer.transform(domSource, result);
            return writer.toString();
        }
        catch (Exception e) {
            throw new S2SException(e.getMessage(),e);
        }
    }
500788
public static Document getSOAPMessage(InputStream in) throws Exception {
        /*
         * ByteArrayOutputStream out = new ByteArrayOutputStream(); int b; while
         * ((b = in.read()) != -1) { out.write(b); }
         * 
         * System.out.println("OUT:" + out.toString());
         */
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
	   // Fortify Mod: Disable entity expansion to foil External Entity Injections
	   dbf.setExpandEntityReferences(false);
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document soapMessage = db.newDocument();
          // Fortify Mod: prevent external entity injection
        TransformerFactory tf = TransformerFactory.newInstance();
        tf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
        Transformer t = tf.newTransformer();
	   // End Fortify Mod
        t.transform(new StreamSource(in), new DOMResult(soapMessage));
        return soapMessage;
    }
1352313
public OutputStream createOutputStream(Number streamId) {
        int channelId = getChannelIdForStreamId(streamId);
        if (log.isTraceEnabled()) {
            log.trace("Create output - stream id: {} channel id: {}", streamId, channelId);
        }
        final Channel data = getChannel(channelId++);
        final Channel video = getChannel(channelId++);
        final Channel audio = getChannel(channelId++);
        if (log.isTraceEnabled()) {
            log.trace("Output stream - data: {} video: {} audio: {}", data, video, audio);
        }
        return new OutputStream(video, audio, data);
    }