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

This code example shows how to use the following methods:
		testFlight(flights); 
	} 
 
	@Test
	public void unmarshalStreamSourceInputStream() throws Exception {
		StreamSource source = new StreamSource(new ByteArrayInputStream(INPUT_STRING.getBytes("UTF-8")));
		Object flights = unmarshaller.unmarshal(source);
		testFlight(flights); 
	} 
 
	@Test
	public void unmarshalStreamSourceReader() throws Exception {
		StreamSource source = new StreamSource(new StringReader(INPUT_STRING));
		Object flights = unmarshaller.unmarshal(source);
		testFlight(flights); 
	} 
} 
 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
	@Test
	public void streamWriterSource() throws Exception {
		StringWriter stringWriter = new StringWriter();
		XMLStreamWriter streamWriter = inputFactory.createXMLStreamWriter(stringWriter);
		Reader reader = new StringReader(XML);
		Source source = new StreamSource(reader);
		StaxResult result = new StaxResult(streamWriter);
		assertEquals("Invalid streamWriter returned", streamWriter, result.getXMLStreamWriter());
		assertNull("EventWriter returned", result.getXMLEventWriter());
		transformer.transform(source, result);
		assertXMLEqual("Invalid result", XML, stringWriter.toString());
	} 
 
	@Test
	public void eventWriterSource() throws Exception {
		StringWriter stringWriter = new StringWriter();
		XMLEventWriter eventWriter = inputFactory.createXMLEventWriter(stringWriter);
		Reader reader = new StringReader(XML);
		Source source = new StreamSource(reader);
		StaxResult result = new StaxResult(eventWriter);
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
	} 
 
 
	@Override 
	public final T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage) throws IOException {
		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 {
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
		testFlights(flights); 
	} 
 
	@Test
	public void unmarshalStreamSourceInputStream() throws Exception {
		StreamSource source = new StreamSource(new ByteArrayInputStream(INPUT_STRING.getBytes("UTF-8")));
		Object flights = unmarshaller.unmarshal(source);
		testFlights(flights); 
	} 
 
	@Test
	public void unmarshalSAXSource() throws Exception {
		XMLReader reader = XMLReaderFactory.createXMLReader();
		SAXSource source = new SAXSource(reader, new InputSource(new StringReader(INPUT_STRING)));
		Object flights = unmarshaller.unmarshal(source);
		testFlights(flights); 
	} 
 
	@Test
	public void unmarshalStaxSourceXmlStreamReader() throws Exception {
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
		} 
		else if (source instanceof Reader) { 
			return new StreamSource((Reader) source); 
		} 
		else if (source instanceof InputStream) { 
			return new StreamSource((InputStream) source); 
		} 
		else if (source instanceof Resource) { 
			Resource resource = (Resource) source; 
			return new StreamSource(resource.getInputStream(), resource.getURI().toASCIIString()); 
		} 
		else { 
			throw new IllegalArgumentException("Value '" + source + "' cannot be converted to XSLT Source"); 
		} 
	} 
 
	/** 
	 * Configure the supplied {@link Transformer} instance. 
	 * <p>The default implementation copies parameters from the model into the 
	 * Transformer's {@link Transformer#setParameter parameter set}. 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
                templates = (Templates)templatesCache.get(xsltURI);
            } 
            if (templates == null) {
                TransformerFactory tf = TransformerFactory.newInstance();
                InputStream input = context.getResourceAsStream(xsltURI);
                templates = tf.newTemplates(new StreamSource(input));
                if (useCache) {
                    templatesCache.put(xsltURI, templates);
                } 
            } 
            return templates.newTransformer();
        } catch (TransformerConfigurationException e) {
            e.printStackTrace();
            throw new RuntimeException(e.toString());
        } 
    } 
 
    // implement ApplicationContext 
    public void init(ServletContextEvent event) {
        this.context = event.getServletContext();
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
		view.afterPropertiesSet(); 
	} 
 
	@Test 
	public void simpleTransformWithSource() throws Exception { 
		Source source = new StreamSource(getProductDataResource().getInputStream()); 
		Map model = new HashMap(); 
		model.put("someKey", source); 
		doTestWithModel(model); 
	} 
 
	@Test 
	public void testSimpleTransformWithDocument() throws Exception { 
		org.w3c.dom.Document document = getDomDocument(); 
		Map model = new HashMap(); 
		model.put("someKey", document); 
		doTestWithModel(model); 
	} 
 
	@Test 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getInputStream
      } 
      final String fn = "xslt/" + filename;
      final TransformerFactory tFactory = TransformerFactory.newInstance();
      tFactory.setURIResolver(new SystemIdResolver(loader).asURIResolver());
      tFactory.setErrorListener(xmllog);
      final StreamSource src = new StreamSource(loader.openResource(fn),
        SystemIdResolver.createSystemIdFromResourceName(fn));
      try { 
        result = tFactory.newTemplates(src);
      } finally { 
        // some XML parsers are broken and don't close the byte stream (but they should according to spec) 
        IOUtils.closeQuietly(src.getInputStream());
      } 
    } catch (Exception e) {
      log.error(getClass().getName(), "newTemplates", e);
      throw new IOException("Unable to initialize Templates '" + filename + "'", e);
    } 
     
    lastFilename = filename;
    lastTemplates = result;
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
                              Unmarshaller u, InputStream entityStream)
            throws JAXBException { 
        if (type.isAnnotationPresent(XmlRootElement.class)) {
            return u.unmarshal(entityStream);
        } else { 
            return u.unmarshal(new StreamSource(entityStream), type).getValue();
        } 
    } 
 
    @Override 
    public final void writeTo( 
            Object t,
            Class<?> type,
            Type genericType,
            Annotation annotations[],
            MediaType mediaType,
            MultivaluedMap<String, Object> httpHeaders,
            OutputStream entityStream) throws IOException {
        try { 
            final Marshaller m = getMarshaller(type, mediaType);
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getInputStream, getReader, getSystemId
	 * @return the object graph 
	 * @throws IOException if an I/O exception occurs 
	 * @throws XmlMappingException if the given source cannot be mapped to an object 
	 */ 
	protected Object unmarshalStreamSource(StreamSource streamSource) throws XmlMappingException, IOException {
		if (streamSource.getInputStream() != null) {
			if (isProcessExternalEntities()) {
				return unmarshalInputStream(streamSource.getInputStream());
			} 
			else { 
				InputSource inputSource = new InputSource(streamSource.getInputStream());
				inputSource.setEncoding(getDefaultEncoding());
				return unmarshalSaxSource(new SAXSource(inputSource));
			} 
		} 
		else if (streamSource.getReader() != null) {
			if (isProcessExternalEntities()) {
				return unmarshalReader(streamSource.getReader());
			} 
			else { 

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Java 8 StreamSource Questions & Answers:

See Code Examples for Java 8 StreamSource Methods: