Package javax.mail.util

Examples of javax.mail.util.ByteArrayDataSource


    {
        final DataHandler dataHandler = part.getDataHandler();
        final DataSource dataSource = dataHandler.getDataSource();
        final String contentType = getBaseMimeType(dataSource.getContentType());
        final byte[] content = this.getContent(dataSource.getInputStream());
        final ByteArrayDataSource result = new ByteArrayDataSource(content, contentType);
        final String dataSourceName = getDataSourceName(part, dataSource);

        result.setName(dataSourceName);
        return result;
    }
View Full Code Here


    {
      // if name == index.html, use this as the emailHTMLBody
      if (repository.isTreatHtmlContentAsBody() && item.getMimeType().endsWith("text/html"))
      {
        final MimeBodyPart messageBodyPart = repository.getBodypart();
        final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, item.getMimeType());
        messageBodyPart.setDataHandler(new DataHandler(dataSource));
      }
      else
      {
        // Normal Content
        final ByteArrayInputStream bin = new ByteArrayInputStream(data);
        final String contentId = (String) item.getContentId();
        final ByteArrayDataSource dataSource = new ByteArrayDataSource(bin, item.getMimeType());
        final MimeBodyPart messageBodyPart = new MimeBodyPart();
        messageBodyPart.setDataHandler(new DataHandler(dataSource));
        messageBodyPart.setHeader("Content-ID", contentId);
        repository.getMultipart().addBodyPart(messageBodyPart);
        bin.close();
View Full Code Here

      }
    }

    final EmailRepository repository = new EmailRepository(session);
    final MimeBodyPart messageBodyPart = repository.getBodypart();
    final ByteArrayDataSource dataSource = new ByteArrayDataSource(bout.toByteArray(), processTask.getReportMimeType());
    messageBodyPart.setDataHandler(new DataHandler(dataSource));

    final int attachmentsSize = mailDefinition.getAttachmentCount();
    for (int i = 0; i < attachmentsSize; i++)
    {
View Full Code Here

         multipPartRoot.addBodyPart(contentPartRoot);
         for (Attachment att : attachment)
         {
            InputStream is = att.getInputStream();
            MimeBodyPart mimeBodyPart = new MimeBodyPart();
            ByteArrayDataSource byteArrayDataSource = new ByteArrayDataSource(is, att.getMimeType());
            mimeBodyPart.setDataHandler(new DataHandler(byteArrayDataSource));

            mimeBodyPart.setDisposition(Part.ATTACHMENT);
            if (att.getName() != null)
               mimeBodyPart.setFileName(MimeUtility.encodeText(att.getName(), "utf-8", null));
View Full Code Here

        // Add text message
        BodyPart messageBodyPart = new MimeBodyPart();
        String text = "Summary\n-------\n\n" + summary + "\n\nDescription\n-----------\n\n" + description;
        messageBodyPart.setText( text );
        messageBodyPart.setDataHandler( new DataHandler( new ByteArrayDataSource( text,
                                                                                  "text/plain; charset=UTF8;" ) ) );
        multipart.addBodyPart( messageBodyPart );

        // Add ical
        messageBodyPart = new MimeBodyPart();
        String filename = "ical-" + type + "-" + taskId + ".ics";
        messageBodyPart.setFileName( filename );
        messageBodyPart.setHeader( "Content-Class",
                                   "urn:content-classes:calendarmessage" );
        messageBodyPart.setHeader( "Content-ID",
                                   "calendar_message" );
        String icalStr = getIcal( summary,
                                  description,
                                  startDate,
                                  priority,
                                  userInfo.getDisplayName( creator ),
                                  creatorEmail,
                                  type );

        messageBodyPart.setDataHandler( new DataHandler( new ByteArrayDataSource( icalStr,
                                                                                  "text/calendar; charset=UTF8; " ) ) );
        multipart.addBodyPart( messageBodyPart );

        message.setContent( multipart );
        message.saveChanges();
View Full Code Here

        if (LOG.isTraceEnabled()) {
            LOG.trace("Using Content-Type " + contentType + " for MimeMessage: " + part);
        }

        // always store content in a byte array data store to avoid various content type and charset issues
        DataSource ds = new ByteArrayDataSource(exchange.getIn().getBody(String.class), contentType);
        part.setDataHandler(new DataHandler(ds));

        // set the content type header afterwards
        part.setHeader("Content-Type", contentType);
View Full Code Here

        if (LOG.isTraceEnabled()) {
            LOG.trace("Using Content-Type " + contentType + " for BodyPart: " + part);
        }

        // always store content in a byte array data store to avoid various content type and charset issues
        DataSource ds = new ByteArrayDataSource(exchange.getIn().getBody(String.class), contentType);
        part.setDataHandler(new DataHandler(ds));

        // set the content type header afterwards
        part.setHeader("Content-Type", contentType);
View Full Code Here

        XopType xop = new XopType();
        xop.setName("xopName");
        InputStream is =
            getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/book.xsd");
        byte[] data = IOUtils.readBytesFromStream(is);
        xop.setAttachinfo(new DataHandler(new ByteArrayDataSource(data, "application/octet-stream")));
       
        String bookXsd = IOUtils.readStringFromStream(getClass().getResourceAsStream(
            "/org/apache/cxf/systest/jaxrs/resources/book.xsd"));
        xop.setAttachinfo2(bookXsd.getBytes());
    
View Full Code Here

                                                                                fileSize);
            }
           
            ((BindingProvider)mtomPort).getRequestContext().put("schema-validation-enabled",
                                                                Boolean.TRUE);
            param.value = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));
            name = new Holder<String>("call detail");
            mtomPort.testXop(name, param);
            assertEquals("name unchanged", "return detail + call detail", name.value);
            assertNotNull(param.value);
           
            in = param.value.getInputStream();
            bytes = IOUtils.readBytesFromStream(in);
            assertEquals(data.length, bytes.length);
            in.close();

            param.value = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));
            name = new Holder<String>("call detail");
            mtomPort.testXop(name, param);
            assertEquals("name unchanged", "return detail + call detail", name.value);
            assertNotNull(param.value);
           
            in = param.value.getInputStream();
            bytes = IOUtils.readBytesFromStream(in);
            assertEquals(data.length, bytes.length);
            in.close();
            ((BindingProvider)mtomPort).getRequestContext().put("schema-validation-enabled",
                                                                Boolean.FALSE);
            SAAJOutInterceptor saajOut = new SAAJOutInterceptor();
            SAAJInInterceptor saajIn = new SAAJInInterceptor();
            param.value = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));
            name = new Holder<String>("call detail");
            mtomPort.testXop(name, param);
            assertEquals("name unchanged", "return detail + call detail", name.value);
            assertNotNull(param.value);
           
            in = param.value.getInputStream();
            bytes = IOUtils.readBytesFromStream(in);
            assertEquals(data.length, bytes.length);
            in.close();
           
            ClientProxy.getClient(mtomPort).getInInterceptors().add(saajIn);
            ClientProxy.getClient(mtomPort).getInInterceptors().add(saajOut);
            param.value = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));
            name = new Holder<String>("call detail");
            mtomPort.testXop(name, param);
            assertEquals("name unchanged", "return detail + call detail", name.value);
            assertNotNull(param.value);
           
View Full Code Here

                this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl").read(data,
                                                                                fileSize * x,
                                                                                fileSize);
            }
           
            param.value = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));
            Holder<String> name = new Holder<String>("call detail");
            mtomPort.testXop(name, param);
            fail("Expect the exception here !");
            assertEquals("name unchanged", "return detail + call detail", name.value);
            assertNotNull(param.value);
View Full Code Here

TOP

Related Classes of javax.mail.util.ByteArrayDataSource

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.