Package javax.activation

Examples of javax.activation.DataSource


        return addAttachment(file.getName(), file);
    }

    public EmailMessage addAttachment(String attachmentName, File file) throws MessagingException {
        BodyPart attachmentPart = new MimeBodyPart();
        DataSource fileDataSource = new FileDataSource(file);
        attachmentPart.setDataHandler(new DataHandler(fileDataSource));
        attachmentPart.setFileName(attachmentName);
        _attachments.add(attachmentPart);
        return this;
    }
View Full Code Here


        for (java.util.Iterator i = orderedAttachments.iterator();
             i.hasNext();) {
            AttachmentPart part = (AttachmentPart) i.next();
            DataHandler dh =
                    AttachmentUtils.getActivationDataHandler(part);
            DataSource ds = dh.getDataSource();

            if ((ds != null) && (ds instanceof ManagedMemoryDataSource)) {
                ((ManagedMemoryDataSource) ds).delete();
            }
        }
View Full Code Here

    protected long getDataSize(DataHandler dh) {
        long dataSize = -1L;

        try {
            DataSource ds = dh.getDataSource();

            //Do files our selfs since this is costly to read in. Ask the file system.
            // This is 90% of the use of attachments.
            if (ds instanceof javax.activation.FileDataSource) {
                javax.activation.FileDataSource fdh =
                    (javax.activation.FileDataSource) ds;
                java.io.File df = fdh.getFile();

                if (!df.exists()) {
                    throw new RuntimeException(
                            JavaUtils.getMessage("noFile",
                                df.getAbsolutePath()));
                }
                dataSize = df.length();
            } else {
                dataSize = 0;
                java.io.InputStream in = ds.getInputStream();
                byte[] readbuf = new byte[64 * 1024];
                int bytesread;

                do {
                    bytesread = in.read(readbuf);
View Full Code Here

    @Override
    public void testHTTPDataSource() throws Exception {
        super.testHTTPDataSource();
        assertEchoInvocation("GreeterHTTPDataSourceProvider");
        Provider<DataSource> provider = (Provider<DataSource>) lookupProvider("GreeterHTTPDataSourceProvider");
        DataSource ejbResponseDataSource = provider.invoke(MessageUtils.createRequestHTTPDataSource());
        AssertUtils.assertResponseHTTPDataSource(ejbResponseDataSource);
    }
View Full Code Here

        else if (soapVersion.equals(SOAPConstants.SOAP_1_2_PROTOCOL))
            Assert.assertEquals(sNameSpaceURI, "http://www.w3.org/2003/05/soap-envelope");
    }

    public static void assertResponseHTTPDataSource(DataSource dataSource) throws Exception {
        DataSource requestDataSource = MessageUtils.createRequestHTTPDataSource();
        Assert.assertEquals(requestDataSource.getContentType(), dataSource.getContentType());
        byte[] expectedBytes = loadBytesFromDataSource(requestDataSource);
        byte[] actualBytes = loadBytesFromDataSource(dataSource);
        Assert.assertEquals(expectedBytes.length, actualBytes.length);
        for (int i = 0; i < expectedBytes.length; i++)
            Assert.assertEquals("Check byte array [" + i + "]", expectedBytes[i], actualBytes[i]);
View Full Code Here

       
    public void testHTTPDataSource() throws Exception {
        Dispatch<DataSource> dispatch = service.createDispatch(GreeterHTTPDataSourcePort,
                                                               DataSource.class,
                                                               Service.Mode.MESSAGE);
        DataSource responseDataSource = dispatch.invoke(MessageUtils.createRequestHTTPDataSource());
        AssertUtils.assertResponseHTTPDataSource(responseDataSource);
    }
View Full Code Here

      Template temp = new Template(name, new InputStreamReader(src), cfg);
      final ByteArrayOutputStream bout = new ByteArrayOutputStream();
      Writer out = new OutputStreamWriter(bout);
      temp.process(renderContext, out);
      out.flush();
      merged = new DataHandler(new DataSource() {
        public InputStream getInputStream() throws IOException {
          return new ByteArrayInputStream(bout.toByteArray());
        }
        public OutputStream getOutputStream() throws IOException {
          return bout;
View Full Code Here

            cache((DelegatingInputStream) body, true);
            message.setContent(InputStream.class, body);
        }

        for (Attachment a : attachments.getLoadedAttachments()) {
            DataSource s = a.getDataHandler().getDataSource();
            if (!(s instanceof AttachmentDataSource)) {
                //AttachementDataSource objects are already cached
                cache((DelegatingInputStream) s.getInputStream(), false);
            }
        }
    }
View Full Code Here

            }
            att.setHeader(header.getName(), header.getValue());
        }
       
        if (quotedPrintable) {
            DataSource source = new AttachmentDataSource(ct, new QuotedPrintableDecoderStream(stream));
            att.setDataHandler(new DataHandler(source));
        } else {
            DataSource source = new AttachmentDataSource(ct, stream);
            att.setDataHandler(new DataHandler(source));
        }
       
        return att;
    }
View Full Code Here

      Template temp = new Template(name, new InputStreamReader(src), cfg);
      final ByteArrayOutputStream bout = new ByteArrayOutputStream();
      Writer out = new OutputStreamWriter(bout);
      temp.process(renderContext, out);
      out.flush();
      merged = new DataHandler(new DataSource() {
        public InputStream getInputStream() throws IOException {
          return new ByteArrayInputStream(bout.toByteArray());
        }
        public OutputStream getOutputStream() throws IOException {
          return bout;
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.