/** * Get the file associated to this attachment * * @return file associated with this attachment (created from the DataSource) or <code>null</code> if there * isn't an underlying file for this attachment. * @deprecated As not all Attachments will have an underlying file this method shouldn't be used. */ public File getFile() { return (dataSource instanceof FileDataSource)?((FileDataSource)dataSource).getFile():null; }
/** * Get the file associated to this attachment * * @return file associated with this attachment (created from the DataSource) or <code>null</code> if there * isn't an underlying file for this attachment. * @deprecated As not all Attachments will have an underlying file this method shouldn't be used. */ public File getFile() { return (dataSource instanceof FileDataSource)?((FileDataSource)dataSource).getFile():null; }
/** * 删除添加的附件 * @return 结果 */ public boolean delFileAffix() { try { FileDataSource fileds = null; for (Iterator<FileDataSource> it = files.iterator(); it.hasNext();) { fileds = it.next(); if (fileds != null && fileds.getFile() != null) { fileds.getFile().delete(); } } return true; } catch (Exception e) { System.err.println("删除邮件附件发生错误:" + e); return false; } }
public idky(FileDataSource ds) { super(ds); len= ds.getFile().length();
class SendMailTLS { // method that contains the attachment block private void sendAttachment(BodyPart messageBodyPart) { // Create a multipar message Multipart multipart = new MimeMultipart(); // Set text message part multipart.addBodyPart(messageBodyPart); // Part two is attachment String attachmentPath = "c:\\doms\\log.txt"; messageBodyPart = new MimeBodyPart(); FileDataSource source = new FileDataSource(attachmentPath); messageBodyPart.setDataHandler(new DataHandler(source)); messageBodyPart.setFileName(source.getFile().getName()); multipart.addBodyPart(messageBodyPart); // Send the complete message parts message.setContent(multipart); } public void sendMail( int httpStatus, ) // ... your code if (httpStatus == 200) { messageBodyPart.setText("OK! The http Status is: " + httpStatus); // execute the private method here and anywhere else you want the same code to run sendAttachment(messageBodyPart); } // ... rest of the code }
return ((FileDataSource)ds).getFile().length(); } else { return -1;
javax.activation.FileDataSource fdh = (javax.activation.FileDataSource) ds; java.io.File df = fdh.getFile();
javax.activation.FileDataSource fdh = (javax.activation.FileDataSource) ds; java.io.File df = fdh.getFile();
javax.activation.FileDataSource fdh = (javax.activation.FileDataSource) ds; java.io.File df = fdh.getFile();
javax.activation.FileDataSource fdh = (javax.activation.FileDataSource) ds; java.io.File df = fdh.getFile();
javax.activation.FileDataSource fdh = (javax.activation.FileDataSource) ds; java.io.File df = fdh.getFile();
javax.activation.FileDataSource fdh = (javax.activation.FileDataSource) ds; java.io.File df = fdh.getFile();
if (ds instanceof FileDataSource) { FileDataSource fds = (FileDataSource)ds; File file = fds.getFile(); if (file.length() < threshold) { return null;
if (ds instanceof FileDataSource) { FileDataSource fds = (FileDataSource)ds; File file = fds.getFile(); if (file.length() < threshold) { return null;
if (ds instanceof FileDataSource) { FileDataSource fds = (FileDataSource)ds; File file = fds.getFile(); if (file.length() < threshold) { return null;
if (ds instanceof FileDataSource) { FileDataSource fds = (FileDataSource)ds; File file = fds.getFile(); if (file.length() < threshold) { return null;
File file = ((FileDataSource) ds).getFile(); builder.addBinaryBody(formData.getName(), file, ct, filename == null ? file.getName() : filename);
if (dataSource instanceof FileDataSource) { FileDataSource fileds = (FileDataSource) dataSource; zipArtifact = zipArtifact.setFile(fileds.getFile());
fileName = ((FileDataSource) dh.getDataSource()).getFile().getName();