Package javax.activation

Examples of javax.activation.DataSource


    }
   
    public void writeTo(Object src, Class cls, Type genericType, Annotation[] annotations,
                        MediaType type, MultivaluedMap headers, OutputStream os)
        throws IOException {
        DataSource ds = DataSource.class.isAssignableFrom(cls)
            ? (DataSource)src : ((DataHandler)src).getDataSource();
        if (useDataSourceContentType) {   
            setContentTypeIfNeeded(type, headers, ds.getContentType());
        }
        IOUtils.copyAndCloseInput(ds.getInputStream(), os);
    }
View Full Code Here


        if (exchange.getIn().hasAttachments()) {
            appendAttachmentsFromCamel(mimeMessage, exchange.getIn(), endpoint.getConfiguration());
        } else {
            if ("text/html".equals(endpoint.getConfiguration().getContentType())) {
                DataSource ds = new ByteArrayDataSource(exchange.getIn().getBody(String.class), "text/html");
                mimeMessage.setDataHandler(new DataHandler(ds));
            } else {
                // its just text/plain
                mimeMessage.setText(exchange.getIn().getBody(String.class));
            }
View Full Code Here

        mixed.addBodyPart(wrap);

        mixed.addBodyPart(plainPart);
        mixed.addBodyPart(htmlPart);

        DataSource ds;
        try {
            File f = new File(getClass().getResource("/log4j.properties").toURI());
            ds = new FileDataSource(f);
        } catch (URISyntaxException ex) {
            ds = new URLDataSource(getClass().getResource("/log4j.properties"));
View Full Code Here

        InOut me = d.createInOutExchange();
        me.getInMessage().setContent(new StringSource("<hello>world</hello>"));
        File f = new File(getClass().getResource("servicemix.jpg").getFile());
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        FileUtil.copyInputStream(new FileInputStream(f), baos);
        DataSource ds = new ByteArrayDataSource(baos.toByteArray(), "image/jpeg");
        DataHandler dh = new DataHandler(ds);
        me.getInMessage().addAttachment("image", dh);
        client.sendSync(me);
        assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
        assertEquals(1, me.getOutMessage().getAttachmentNames().size());
View Full Code Here

        JAXBContext context = db.getContext();
        return callSWARefMethod(context);
    }

    private DataSource createDataSource(Source o, String ct) {
        DataSource ds = null;
       
        if (o instanceof StreamSource) {
            StreamSource src = (StreamSource)o;
            try {
                if (src.getInputStream() != null) {
View Full Code Here

        };
    }
   
    public final class Extractor {
        public String extractName(DataHandler body) {
            DataSource ds = (body != null) ? body.getDataSource() : null;
            if (ds != null && ds instanceof FileDataSource) {
                return ((FileDataSource)ds).getName();
            }
            return null;
        }
View Full Code Here

        this.contentType = contentType;
    }

    public void readMessage(MessageExchange exchange, NormalizedMessage message,
                            InputStream in, String path) throws IOException, JBIException {
        DataSource ds = new StreamDataSource(in, contentType);
        DataHandler handler = new DataHandler(ds);
        message.addAttachment(attachment, handler);
        message.setProperty(FILE_NAME_PROPERTY, new File(path).getName());
        message.setProperty(FILE_PATH_PROPERTY, path);
    }
View Full Code Here

    }
   
    private static void copyAttachments(NormalizedMessage from, NormalizedMessage to) throws MessagingException {
        for (Object name : from.getAttachmentNames()) {
            DataHandler handler = from.getAttachment((String)name);
            DataSource source = handler.getDataSource();
            if (!(source instanceof ByteArrayDataSource)) {
                DataSource copy = copyDataSource(source);
                handler = new DataHandler(copy);
            }
            to.addAttachment((String)name, handler);
        }
    }
View Full Code Here

    private void convertAttachments() throws IOException {
        if (attachments != null) {
            Map newAttachments = createAttachmentsMap();
            for (Iterator it = attachments.keySet().iterator(); it.hasNext();) {
                String name = (String) it.next();
                DataSource ds = (DataSource) attachments.get(name);
                if (ds instanceof ByteArrayDataSource) {
                    newAttachments.put(name, ds);
                } else {
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    FileUtil.copyInputStream(ds.getInputStream(), baos);
                    ByteArrayDataSource bads = new ByteArrayDataSource(baos.toByteArray(), ds.getContentType());
                    bads.setName(ds.getName());
                    newAttachments.put(name, bads);
                }
            }
            attachments = newAttachments;
        }
View Full Code Here

                    this.properties.put(name, message.getProperty(name));
                }
                for (Iterator it = message.getAttachmentNames().iterator(); it.hasNext();) {
                    String name = (String) it.next();
                    DataHandler dh = message.getAttachment(name);
                    DataSource ds = dh.getDataSource();
                    if (!(ds instanceof ByteArrayDataSource)) {
                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
                        FileUtil.copyInputStream(ds.getInputStream(), baos);
                        ByteArrayDataSource bads = new ByteArrayDataSource(baos.toByteArray(), ds.getContentType());
                        bads.setName(ds.getName());
                        dh = new DataHandler(bads);
                    }
                    this.attachments.put(name, dh);
                }
                this.subject = message.getSecuritySubject();
View Full Code Here

TOP

Related Classes of javax.activation.DataSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.