@Override public StreamSource readFrom( Class<StreamSource> t, Type gt, Annotation[] as, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { return new StreamSource(entityStream); } }
/** * Create the XSLT {@link Result} used to render the result of the transformation. * <p>The default implementation creates a {@link StreamResult} wrapping the supplied * HttpServletResponse's {@link HttpServletResponse#getOutputStream() OutputStream}. * @param response current HTTP response * @return the XSLT Result to use * @throws Exception if the Result cannot be built */ protected Result createResult(HttpServletResponse response) throws Exception { return new StreamResult(response.getOutputStream()); }
/** * Construct a StreamResult from a File. * * @param f Must a non-null File reference. */ public StreamResult(File f) { setSystemId(f); }
@Test public void jettisonDriver() throws Exception { marshaller.setStreamDriver(new JettisonMappedXmlDriver()); Writer writer = new StringWriter(); marshaller.marshal(flight, new StreamResult(writer)); assertEquals("Invalid result", "{\"flight\":{\"flightNumber\":42}}", writer.toString()); Object o = marshaller.unmarshal(new StreamSource(new StringReader(writer.toString()))); assertTrue("Unmarshalled object is not Flights", o instanceof Flight); Flight unflight = (Flight) o; assertNotNull("Flight is null", unflight); assertEquals("Number is invalid", 42L, unflight.getFlightNumber()); }
@Override protected Object unmarshalStreamSource(StreamSource streamSource) throws XmlMappingException, IOException { if (streamSource.getInputStream() != null) { return unmarshalInputStream(streamSource.getInputStream()); } else if (streamSource.getReader() != null) { return unmarshalReader(streamSource.getReader()); } else { throw new IllegalArgumentException("StreamSource contains neither InputStream nor Reader"); } }
/** * Construct a StreamSource from a File. * * @param f Must a non-null File reference. */ public StreamSource(File f) { setSystemId(f); }
/** * Construct a StreamResult from a byte stream. Normally, * a stream should be used rather than a reader, so that * the transformer may use instructions contained in the * transformation instructions to control the encoding. * * @param outputStream A valid OutputStream reference. */ public StreamResult(OutputStream outputStream) { setOutputStream(outputStream); }
@Override public StreamSource readFrom( Class<StreamSource> t, Type gt, Annotation[] as, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { return new StreamSource(entityStream); } }
@Override @Nullable protected Long getContentLength(T t, @Nullable MediaType contentType) { if (t instanceof DOMSource) { try { CountingOutputStream os = new CountingOutputStream(); transform(t, new StreamResult(os)); return os.count; } catch (TransformerException ex) { // ignore } } return null; }
Source source = new StreamSource(inputStream); JAXBElement<FooClass> root = unmarshaller.unmarshal(source, FooClass.class); FooClass foo = root.getValue();
@Override protected void writeInternal(T t, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { try { Result result = new StreamResult(outputMessage.getBody()); transform(t, result); } catch (TransformerException ex) { throw new HttpMessageNotWritableException("Could not transform [" + t + "] to output message", ex); } }
private Source getSource(Object payload) { if (payload instanceof byte[]) { return new StreamSource(new ByteArrayInputStream((byte[]) payload)); } else { return new StreamSource(new StringReader((String) payload)); } }
@Test(expected = XmlMappingException.class) public void marshalInvalidClass() throws Exception { Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); marshaller.setClassesToBeBound(FlightType.class); marshaller.afterPropertiesSet(); Result result = new StreamResult(new StringWriter()); Flights flights = new Flights(); marshaller.marshal(flights, result); }
protected int run() throws Exception { job.updateByXml((Source)new StreamSource(stdin)); return 0; } }
@Override protected int run() throws Exception { view.updateByXml(new StreamSource(stdin)); return 0; } }
private StreamSource readStreamSource(InputStream body) throws IOException { byte[] bytes = StreamUtils.copyToByteArray(body); return new StreamSource(new ByteArrayInputStream(bytes)); }
/** * Unmarshal the given {@link TextMessage} into an object. * @param message the message * @param unmarshaller the unmarshaller to use * @return the unmarshalled object * @throws JMSException if thrown by JMS methods * @throws IOException in case of I/O errors * @throws XmlMappingException in case of OXM mapping errors * @see Unmarshaller#unmarshal(Source) */ protected Object unmarshalFromTextMessage(TextMessage message, Unmarshaller unmarshaller) throws JMSException, IOException, XmlMappingException { Source source = new StreamSource(new StringReader(message.getText())); return unmarshaller.unmarshal(source); }
@Test public void unmarshalStreamSourceReader() throws Exception { StreamSource source = new StreamSource(new StringReader(INPUT_STRING)); Object flights = unmarshaller.unmarshal(source); testFlight(flights); } }
@Test public void simpleTransformWithSource() throws Exception { Source source = new StreamSource(getProductDataResource().getInputStream()); doTestWithModel(singletonMap("someKey", source)); }
@Test public void unmarshalStreamSourceReader() throws Exception { StreamSource source = new StreamSource(new StringReader(INPUT_STRING)); Object flights = unmarshaller.unmarshal(source); testFlights(flights); }