Java 8 LSOutput - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 LSOutput class.

This code example shows how to use the following methods:setByteStream, setEncoding
                        Boolean.TRUE)) {
                    lsSerializer.getDomConfig().setParameter(
                            "format-pretty-print", Boolean.TRUE);
                    final LSOutput lsOutput = domImplementationLS
                            .createLSOutput();
                    lsOutput.setEncoding("UTF-8");
                    lsOutput.setByteStream(outputStream);
                    try { 
                        lsSerializer.write(document, lsOutput);
                    } 
                    catch (final LSException lse) {
                        throw new IllegalStateException(lse);
                    } 
                    finally { 
                        IOUtils.closeQuietly(outputStream);
                    } 
                } 
                else { 
                    // DOMConfiguration 'format-pretty-print' parameter not 
                    // available. Falling back to TrAX. 
6
CodeRank
This code example shows how to use the following methods:setByteStream, setEncoding
            if (lss.getDomConfig().canSetParameter("format-pretty-print", true))
            { 
                lss.getDomConfig().setParameter("format-pretty-print", true);
                 
                final LSOutput lsOut = domImplLS.createLSOutput();
                lsOut.setEncoding("UTF-8");
                lsOut.setByteStream(out);
                 
                lss.write(node, lsOut);
            } 
            else 
            { 
                logger.warn("DOMConfiguration 'format-pretty-print' parameter isn't settable. Won't pretty print."); 
                write(node, out);
            } 
        } 
        else 
        { 
            logger.warn("DOM 3.0 LS and/or DOM 2.0 Core not supported. Won't pretty print."); 
            write(node, out);
6
CodeRank
This code example shows how to use the following methods:setCharacterStream, setEncoding
			LSSerializer lsSerializer = domImplementationLS.createLSSerializer();
			DOMConfiguration domConfiguration = lsSerializer.getDomConfig();
			if (domConfiguration.canSetParameter("format-pretty-print", Boolean.TRUE)) {
				lsSerializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
				LSOutput lsOutput = domImplementationLS.createLSOutput();
				lsOutput.setEncoding("UTF-8");
				StringWriter stringWriter = new StringWriter();
				lsOutput.setCharacterStream(stringWriter);
				lsSerializer.write(doc, lsOutput);
				return stringWriter.toString();
			} else { 
				throw new RuntimeException(
						"DOMConfiguration 'format-pretty-print' parameter isn't settable."); 
			} 
		} else { 
			throw new RuntimeException("DOM 3.0 LS and/or DOM 2.0 Core not supported.");
		} 
	} 
 
	private static Document parseXMLString(String in) {
6
CodeRank
This code example shows how to use the following methods:setByteStream, setEncoding
        return parse(xmlStream);
    } 
 
    public static void serialize(Node xml, OutputStream out) {
        LSOutput ouput = getOuput();
        ouput.setEncoding("utf-8");
        ouput.setByteStream(out);
 
        getSerializer().write(xml, ouput);
    } 
 
    public static String serializeString(Node xml) {
        return getSerializer().writeToString(xml);
    } 
 
    public static InputStream serializeStream(Node xml) {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream(10000);
        serialize(xml, outputStream);
        return new ByteArrayInputStream(outputStream.toByteArray());
    } 
6
CodeRank
This code example shows how to use the following methods:setByteStream, setEncoding
		return doc;
	} 
	 
	public static void outputDocument(Document doc, OutputStream os) {
		 LSOutput domOutput = domImpl.createLSOutput();
         domOutput.setByteStream(os);
         domOutput.setEncoding("UTF-8");
          
         serializer.write(doc, domOutput); 
	} 
	 
 
	/** 
	 * Transform XML from byte[] to {@link Document} 
	 *  
	 * @param xml 
	 *            The XML in form of byte array 
	 * @return XML {@link Document} or null on error 
	 */ 
	public static Document byteArray2doc(byte[] xml) {
6
CodeRank
This code example shows how to use the following methods:setByteStream, setEncoding
		return doc;
	} 
	 
	public static void outputDocument(Document doc, OutputStream os) {
		 LSOutput domOutput = domImpl.createLSOutput();
         domOutput.setByteStream(os);
         domOutput.setEncoding("UTF-8");
          
         serializer.write(doc, domOutput); 
	} 
	 
 
	/** 
	 * Transform XML from byte[] to {@link Document} 
	 *  
	 * @param xml 
	 *            The XML in form of byte array 
	 * @return XML {@link Document} or null on error 
	 */ 
	public static Document byteArray2doc(byte[] xml) {
6
CodeRank
This code example shows how to use the following methods:setByteStream
            DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
            DOMImplementationLS impl =
                    (DOMImplementationLS) registry.getDOMImplementation("LS");
            LSSerializer writer = impl.createLSSerializer();
            LSOutput output = impl.createLSOutput();
            output.setByteStream(byteArrayOutputStrm);
            writer.write(element, output);
            return byteArrayOutputStrm.toString();
        } catch (Exception e) {
            log.error("Error Serializing the SAML Response");
            throw new IdentityException("Error Serializing the SAML Response", e);
        } 
    } 
 
    private static Issuer getIssuer() { 
        Issuer issuer = new IssuerBuilder().buildObject();
        issuer.setValue("WSO2 Identity Server");
        issuer.setFormat("urn:oasis:names:tc:SAML:2.0:nameid-format:entity");
        return issuer;
    } 
5
CodeRank
This code example shows how to use the following methods:setCharacterStream, setEncoding
			LSSerializer lsSerializer = domImplementationLS.createLSSerializer();
			DOMConfiguration domConfiguration = lsSerializer.getDomConfig();
			if (domConfiguration.canSetParameter("format-pretty-print", Boolean.TRUE)) {
				lsSerializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
				LSOutput lsOutput = domImplementationLS.createLSOutput();
				lsOutput.setEncoding("UTF-8");
				StringWriter stringWriter = new StringWriter();
				lsOutput.setCharacterStream(stringWriter);
				lsSerializer.write(doc, lsOutput);
				return stringWriter.toString();
			} else { 
				throw new RuntimeException("DOMConfiguration 'format-pretty-print' parameter isn't settable.");
			} 
		} else { 
			throw new RuntimeException("DOM 3.0 LS and/or DOM 2.0 Core not supported.");
		} 
	} 
 
	public static String lsSerialize(Document doc) {
		DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
5
CodeRank
This code example shows how to use the following methods:setByteStream
This code example shows how to use the following methods:setCharacterStream, setEncoding
See Code Examples for Java 8 LSOutput Methods: