Package javax.activation

Examples of javax.activation.FileDataSource


        // check if a FileDataSource for this name has already been attached;
        // if so, return the cached CID value.
        if (inlineEmbeds.containsKey(file.getName()))
        {
            final InlineImage ii = inlineEmbeds.get(file.getName());
            final FileDataSource fileDataSource = (FileDataSource) ii.getDataSource();
            // make sure the supplied file has the same canonical path
            // as the one already associated with this name.
            String existingFilePath = null;
            try
            {
                existingFilePath = fileDataSource.getFile().getCanonicalPath();
            }
            catch (final IOException ioe)
            {
                throw new EmailException("couldn't get canonical path for file "
                        + fileDataSource.getFile().getName()
                        + "which has already been embedded", ioe);
            }
            if (filePath.equals(existingFilePath))
            {
                return ii.getCid();
            }
            else
            {
                throw new EmailException("embedded name '" + file.getName()
                    + "' is already bound to file " + existingFilePath
                    + "; existing names cannot be rebound");
            }
        }

        // verify that the file is valid
        if (!file.exists())
        {
            throw new EmailException("file " + filePath + " doesn't exist");
        }
        if (!file.isFile())
        {
            throw new EmailException("file " + filePath + " isn't a normal file");
        }
        if (!file.canRead())
        {
            throw new EmailException("file " + filePath + " isn't readable");
        }

        return embed(new FileDataSource(file), file.getName(), cid);
    }
View Full Code Here


            if (!file.exists())
            {
                throw new IOException("\"" + fileName + "\" does not exist");
            }

            final FileDataSource fds = new FileDataSource(file);

            return attach(fds, file.getName(), null, EmailAttachment.ATTACHMENT);
        }
        catch (final IOException e)
        {
View Full Code Here

                {
                    throw new IOException("\"" + fileName + "\" does not exist");
                }
                result =
                    attach(
                        new FileDataSource(file),
                        attachment.getName(),
                        attachment.getDescription(),
                        attachment.getDisposition());
            }
            catch (final IOException e)
View Full Code Here

        // ====================================================================

        final File tmpFile = File.createTempFile("attachment", ".eml");
       
        this.email.attach(
                new FileDataSource(tmpFile),
                "Test Attachment",
                "Test Attachment Desc");

        assertTrue(tmpFile.delete());
    }
View Full Code Here

        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

                if (!file.exists() || !file.canRead()) {
                    throw new BuildException("File \"" + file.getAbsolutePath()
                         + "\" does not exist or is not "
                         + "readable.");
                }
                FileDataSource fileData = new FileDataSource(file);
                DataHandler fileDataHandler = new DataHandler(fileData);

                body.setDataHandler(fileDataHandler);
                body.setFileName(file.getName());
                attachments.addBodyPart(body);
View Full Code Here

    public static Source createResponseHTTPSource() {
        return new StreamSource(new StringReader(ResponseMessagePayload));
    }

    public static DataSource createRequestHTTPDataSource() throws IOException {
        return new FileDataSource(new File(MessageUtils.class.getResource("/geronimo.txt").getFile()));       
    }
View Full Code Here

    public static DataSource createRequestHTTPDataSource() throws IOException {
        return new FileDataSource(new File(MessageUtils.class.getResource("/geronimo.txt").getFile()));       
    }

    public static DataSource createResponseHTTPDataSource() throws IOException {
        return new FileDataSource(new File(MessageUtils.class.getResource("/geronimo.txt").getFile()));
    }
View Full Code Here

      // @BURMEBJ002A end

      for (int i = 0; i < attachements.length; i++) {
        MimeBodyPart file_part = new MimeBodyPart();
        java.io.File file = attachements[i];
        FileDataSource fds = new FileDataSource(file);
        DataHandler dh = new DataHandler(fds);
        // @BURMEBJ002M begin
        String fileName = file.getName();
        if (i < numberOfFileNames && fileNames[i] != null) {
          fileName = fileNames[i];
View Full Code Here

    @Override
    public final Attachment addAttachment(String contentId, File file) throws AttachmentException {
        Assert.hasLength(contentId, "contentId must not be empty");
        Assert.notNull(file, "File must not be null");
        DataHandler dataHandler = new DataHandler(new FileDataSource(file));
        return addAttachment(contentId, dataHandler);
    }
View Full Code Here

TOP

Related Classes of javax.activation.FileDataSource

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.