Java 8 StreamResult - 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 StreamResult class.

This code example shows how to use the following methods:
This code example shows how to use the following methods:
		XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(XML));
		StaxSource source = new StaxSource(streamReader);
		assertEquals("Invalid streamReader returned", streamReader, source.getXMLStreamReader());
		assertNull("EventReader returned", source.getXMLEventReader());
		StringWriter writer = new StringWriter();
		transformer.transform(source, new StreamResult(writer));
		assertXMLEqual("Invalid result", XML, writer.toString());
	} 
 
	@Test
	public void streamReaderSourceToDOMResult() throws Exception {
		XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(XML));
		StaxSource source = new StaxSource(streamReader);
		assertEquals("Invalid streamReader returned", streamReader, source.getXMLStreamReader());
		assertNull("EventReader returned", source.getXMLEventReader());
 
		Document expected = documentBuilder.parse(new InputSource(new StringReader(XML)));
		Document result = documentBuilder.newDocument();
		transformer.transform(source, new DOMResult(result));
		assertXMLEqual("Invalid result", expected, result);
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getWriter
This code example shows how to use the following methods:
        StringWriter writer = new StringWriter();
        try { 
            TransformerFactory factory = TransformerFactory.newInstance();
            Transformer transformer = factory.newTransformer();
            DOMSource domSource = new DOMSource(document);
            StreamResult streamResult = new StreamResult(writer);
            transformer.transform(domSource, streamResult); 
        } catch (TransformerException e) {
            throw new RuntimeException(
                    "Error when serializing XML document.", e);
        } 
        return writer.toString();
    } 
 
    /** 
     * Parse an XML file to DOM 
     * @return null if an error occurs during parsing. 
     *  
     */ 
    public static Document getDocument(File file) {
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
		return flightsDocument; 
	} 
 
	@Test(expected = ClassCastException.class) 
	public void testMarshalNonXmlObject() throws Exception { 
		marshaller.marshal(new Object(), new StreamResult(new ByteArrayOutputStream())); 
	} 
 
	@Test 
	public void supports() throws Exception { 
		assertTrue("XmlBeansMarshaller does not support XmlObject", marshaller.supports(XmlObject.class)); 
		assertFalse("XmlBeansMarshaller supports other objects", marshaller.supports(Object.class)); 
		assertTrue("XmlBeansMarshaller does not support FlightsDocument", marshaller.supports(FlightsDocument.class)); 
		assertTrue("XmlBeansMarshaller does not support Flights", marshaller.supports(FlightsDocument.Flights.class)); 
		assertTrue("XmlBeansMarshaller does not support FlightType", marshaller.supports(FlightType.class)); 
	} 
 
} 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
	} 
 
	@Test
	public void noNamespacePrefixes() throws Exception {
		StringWriter stringWriter = new StringWriter();
		AbstractStaxHandler handler = createStaxHandler(new StreamResult(stringWriter));
		xmlReader.setContentHandler(handler);
		xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
 
		xmlReader.setFeature("http://xml.org/sax/features/namespaces", true);
		xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
 
		xmlReader.parse(new InputSource(new StringReader(COMPLEX_XML)));
 
		assertXMLEqual(COMPLEX_XML, stringWriter.toString());
	} 
 
	@Test
	public void namespacePrefixes() throws Exception {
		StringWriter stringWriter = new StringWriter();
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
		return readFromSource(clazz, inputMessage.getHeaders(), new StreamSource(inputMessage.getBody()));
	} 
 
	@Override 
	protected final void writeInternal(T t, HttpOutputMessage outputMessage) throws IOException {
		writeToResult(t, outputMessage.getHeaders(), new StreamResult(outputMessage.getBody()));
	} 
 
	/** 
	 * Transforms the given {@code Source} to the {@code Result}. 
	 * @param source the source to transform from 
	 * @param result the result to transform to 
	 * @throws TransformerException in case of transformation errors 
	 */ 
	protected void transform(Source source, Result result) throws TransformerException {
		this.transformerFactory.newTransformer().transform(source, result);
	} 
 
 
	/** 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
    // test QueueConfigurationParser.getQueueElement  
    Element e = QueueConfigurationParser.getQueueElement(document, info);
    // transform result to string for check 
    DOMSource domSource = new DOMSource(e);
    StringWriter writer = new StringWriter();
    StreamResult result = new StreamResult(writer);
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer transformer = tf.newTransformer();
    transformer.transform(domSource, result);
    String str= writer.toString();
    assertTrue(str
        .endsWith("<queue><name>root</name><properties/><state>running</state><queue><name>child1</name><properties/><state>running</state></queue><queue><name>child2</name><properties/><state>running</state></queue></queue>"));
  } 
} 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getWriter
      */ 
      public static String document2String(Element element) {
	  	String result = null;
 
	  	StringWriter strWtr = new StringWriter();
        StreamResult strResult = new StreamResult(strWtr);
        TransformerFactory tfac = TransformerFactory.newInstance();
        try { 
	      Transformer trans = tfac.newTransformer();
	      trans.setOutputProperty("omit-xml-declaration","yes");
	      trans.transform(new DOMSource(element), strResult);
	  } catch (Exception e) {
	      System.err.println("XMLUtils.document2String(): " + e);
	  } 
	  result = strResult.getWriter().toString();
 
	  return result;
      }//document2String() 
 
} 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
	} 
 
	@Test
	public void marshalStreamResultWriter() throws Exception {
		StringWriter writer = new StringWriter();
		StreamResult result = new StreamResult(writer);
		marshaller.marshal(flights, result);
		assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
	} 
 
	@Test
	public void marshalStreamResultOutputStream() throws Exception {
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		StreamResult result = new StreamResult(os);
		marshaller.marshal(flights, result);
		assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING,
				new String(os.toByteArray(), "UTF-8"));
	} 
 
	@Test
9
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Java 8 StreamResult Questions & Answers:

See Code Examples for Java 8 StreamResult Methods: