当前位置: 首页>>代码示例>>Java>>正文


Java BodyPart.getInputStream方法代码示例

本文整理汇总了Java中javax.mail.BodyPart.getInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java BodyPart.getInputStream方法的具体用法?Java BodyPart.getInputStream怎么用?Java BodyPart.getInputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.mail.BodyPart的用法示例。


在下文中一共展示了BodyPart.getInputStream方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: saveAttachment

import javax.mail.BodyPart; //导入方法依赖的package包/类
/** 
 * ���渽�� 
 * @param part �ʼ��ж��������е�����һ������� 
 * @param destDir  ��������Ŀ¼ 
 */ 
public static void saveAttachment(Part part, String destDir) throws UnsupportedEncodingException, MessagingException, 
        FileNotFoundException, IOException { 
    if (part.isMimeType("multipart/*")) { 
        Multipart multipart = (Multipart) part.getContent();    //�������ʼ� 
        //�������ʼ���������ʼ��� 
        int partCount = multipart.getCount(); 
        for (int i = 0; i < partCount; i++) { 
            //��ø������ʼ�������һ���ʼ��� 
            BodyPart bodyPart = multipart.getBodyPart(i); 
            //ijһ���ʼ���Ҳ�п������ɶ���ʼ�����ɵĸ����� 
            String disp = bodyPart.getDisposition(); 
            if (disp != null && (disp.equalsIgnoreCase(Part.ATTACHMENT) || disp.equalsIgnoreCase(Part.INLINE))) { 
                InputStream is = bodyPart.getInputStream(); 
                saveFile(is, destDir, decodeText(bodyPart.getFileName())); 
            } else if (bodyPart.isMimeType("multipart/*")) { 
                saveAttachment(bodyPart,destDir); 
            } else { 
                String contentType = bodyPart.getContentType(); 
                if (contentType.indexOf("name") != -1 || contentType.indexOf("application") != -1) { 
                    saveFile(bodyPart.getInputStream(), destDir, decodeText(bodyPart.getFileName())); 
                } 
            } 
        } 
    } else if (part.isMimeType("message/rfc822")) { 
        saveAttachment((Part) part.getContent(),destDir); 
    } 
}
 
开发者ID:bjut-2014,项目名称:scada,代码行数:33,代码来源:MailUtils.java

示例2: saveAttachment

import javax.mail.BodyPart; //导入方法依赖的package包/类
/**
 * 保存附件
 * @param part 邮件中多个组合体中的其中一个组合体
 * @param destDir  附件保存目录
 * @throws UnsupportedEncodingException
 * @throws MessagingException
 * @throws FileNotFoundException
 * @throws IOException
 */
public static void saveAttachment(Part part, String destDir) throws UnsupportedEncodingException, MessagingException,
		FileNotFoundException, IOException {
	if (part.isMimeType("multipart/*")) {
		Multipart multipart = (Multipart) part.getContent();	//复杂体邮件
		//复杂体邮件包含多个邮件体
		int partCount = multipart.getCount();
		for (int i = 0; i < partCount; i++) {
			//获得复杂体邮件中其中一个邮件体
			BodyPart bodyPart = multipart.getBodyPart(i);
			//某一个邮件体也有可能是由多个邮件体组成的复杂体
			String disp = bodyPart.getDisposition();
			if (disp != null && (disp.equalsIgnoreCase(Part.ATTACHMENT) || disp.equalsIgnoreCase(Part.INLINE))) {
				InputStream is = bodyPart.getInputStream();
				saveFile(is, destDir, decodeText(bodyPart.getFileName()));
			} else if (bodyPart.isMimeType("multipart/*")) {
				saveAttachment(bodyPart,destDir);
			} else {
				String contentType = bodyPart.getContentType();
				if (contentType.indexOf("name") != -1 || contentType.indexOf("application") != -1) {
					saveFile(bodyPart.getInputStream(), destDir, decodeText(bodyPart.getFileName()));
				}
			}
		}
	} else if (part.isMimeType("message/rfc822")) {
		saveAttachment((Part) part.getContent(),destDir);
	}
}
 
开发者ID:xiaomin0322,项目名称:alimama,代码行数:37,代码来源:POP3ReceiveMailTest.java

示例3: saveFile

import javax.mail.BodyPart; //导入方法依赖的package包/类
/**
 * �����Ĵ������ϴ�
 */
private void saveFile(Message message, BodyPart bp) throws Exception {
	String fileName = bp.getFileName();
	if ((fileName != null)) {
		new File(dir).mkdirs(); // �½�Ŀ¼
		fileName = MimeUtility.decodeText(fileName);
		String suffix = fileName.substring(fileName.lastIndexOf("."));
		String filePath = dir + "/" + UUID.randomUUID() + suffix;
		message.attachMap.put(fileName, filePath);

		File file = new File(filePath);
		BufferedInputStream bis = new BufferedInputStream(bp.getInputStream());
		BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
		int i;
		while ((i = bis.read()) != -1) {
			bos.write(i);
		}
		bos.close();
		bis.close();
	}
}
 
开发者ID:toulezu,项目名称:play,代码行数:24,代码来源:MailHelper.java

示例4: save

import javax.mail.BodyPart; //导入方法依赖的package包/类
private void save(Store store, String wheretobackup, String f) throws MessagingException, IOException {

	    System.out.println("opening folder " + f);
	    Folder folder = store.getFolder(f);
	    folder.open(Folder.READ_ONLY);

	    FileUtils.forceMkdir(new File(wheretobackup));

		// Get directory
		Message message[] = folder.getMessages();
		for (int i = 0, n = message.length; i < n; i++) {
			// String from = (message[i].getFrom()[0]).toString();
			String subj = (message[i].getSubject()).toString();
			String nota = (message[i].getContent()).toString();

			if (message[i].getContent() instanceof MimeMultipart) {

				MimeMultipart multipart = (MimeMultipart) message[i].getContent();

				for (int j = 0; j < multipart.getCount(); j++) {

					BodyPart bodyPart = multipart.getBodyPart(j);
						
						if (bodyPart.isMimeType("text/html")) {
							nota = bodyPart.getContent().toString();
							generals.writeFile(wheretobackup + "/" + generals.makeFilename(subj).trim() + ".html", nota, message[i].getSentDate());
							
						} else if (bodyPart.isMimeType("IMAGE/PNG")) {
							String imagecid = ((MimePart) bodyPart).getContentID();
							
							InputStream is = bodyPart.getInputStream();
						    FileUtils.forceMkdir(new File(wheretobackup + "/images/"));
							File fimg = new File(wheretobackup + "/images/" + bodyPart.getFileName());
							System.out.println("saving " + wheretobackup + "/images/" + bodyPart.getFileName());
					        FileOutputStream fos = new FileOutputStream(fimg);
					        byte[] buf = new byte[4096];
					        int bytesRead;
					        while((bytesRead = is.read(buf))!=-1) {
					            fos.write(buf, 0, bytesRead);
					        }
					        fos.close();
					        
					        
					        // devi fare il replace 0DA094B7-933A-4B19-947F-2FC42FA9DABD
							System.out.println("html replace file name : " + imagecid);							
							System.out.println("into file name : " + bodyPart .getFileName());							

						}
				}
			} else {
				generals.writeFile(wheretobackup + "/" + generals.makeFilename(subj).trim() + ".html", nota, message[i].getSentDate());
			}
		}
		folder.close(false);
	}
 
开发者ID:edoardoc,项目名称:iCloudNotes,代码行数:56,代码来源:NotesSaver.java

示例5: getPartByteBuffer

import javax.mail.BodyPart; //导入方法依赖的package包/类
public ByteBuffer getPartByteBuffer(String index) {
    BodyPart part = getPart(index);
    if (part != null) {
        try {
            InputStream stream = part.getInputStream();
            return getByteBufferFromStream(stream);
        } catch (Exception e) {
            Debug.logError(e, module);
            return null;
        }
    } else {
        return null;
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:15,代码来源:MimeMessageWrapper.java

示例6: extractIndex

import javax.mail.BodyPart; //导入方法依赖的package包/类
static DisambiguatedDocument extractIndex(MimeMultipart mmp, int index) throws MessagingException, IOException {
  // Retrieve the body part. If encoded with "gzip", decode it.
  // We want to copy into into the byte buffer stored in the response
  BodyPart doc = mmp.getBodyPart(index);     
  String encoding = null;
  String[] encodings = doc.getHeader("Content-Encoding");
  if (encodings != null && encodings.length == 1 && encodings[0].contentEquals("gzip"))
    encoding = encodings[0];
  return new DisambiguatedDocument(doc.getContentType(), encoding, doc.getInputStream());
}
 
开发者ID:Idilia,项目名称:idilia-java-sdk,代码行数:11,代码来源:DisambiguateCodec.java

示例7: getFileInputStream

import javax.mail.BodyPart; //导入方法依赖的package包/类
public InputStream getFileInputStream(String name) throws IOException {
  BodyPart part = getBodyPart(name);
  try {
    return part.getInputStream();
  } catch (MessagingException e) {
    throw new IOException(e.getMessage());
  }
}
 
开发者ID:thinkberg,项目名称:snipsnap,代码行数:9,代码来源:MultipartWrapper.java

示例8: createMessage

import javax.mail.BodyPart; //导入方法依赖的package包/类
/**
 * Creates a MIME message from a SOAP message.
 * 
 * @param from the 'from' mail address.
 * @param to the 'to' mail address(es).
 * @param cc the 'cc' mail address(es).
 * @param subject the mail subject.
 * @param soapMessage the SOAP message.
 * @param session the mail session.
 * @return a new MIME message.
 * @throws ConnectionException if error occurred in constructing the mail
 *             message.
 * @see hk.hku.cecid.piazza.commons.net.MailSender#createMessage(java.lang.String, java.lang.String, java.lang.String, java.lang.String, javax.mail.Session)
 */
public MimeMessage createMessage(String from, String to, String cc,
        String subject, SOAPMessage soapMessage, Session session) throws ConnectionException {
    try {
        MimeMessage message = super.createMessage(from, to, cc, subject, session);
        
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        soapMessage.writeTo(bos);
        String contentType = getContentType(soapMessage);
        
        ByteArrayDataSource content = new ByteArrayDataSource(bos.toByteArray(), contentType);
        soapMessage.getAttachments();
        boolean hasAttachments = soapMessage.countAttachments() > 0;
        if (hasAttachments) {
            putHeaders(soapMessage.getMimeHeaders(), message);
            MimeMultipart mmp = new MimeMultipart(content);
            for (int i=0; i<mmp.getCount(); i++) {
                BodyPart bp = mmp.getBodyPart(i);

                // encoding all parts in base64 to overcome length of character line limitation in SMTP
                InputStreamDataSource isds = new InputStreamDataSource(
                	bp.getInputStream(), bp.getContentType(), bp.getFileName());
                bp.setDataHandler(new DataHandler(isds));
                bp.setHeader("Content-Transfer-Encoding", "base64");              
            }
            message.setContent(mmp);
        }
        else {
            DataHandler dh = new DataHandler(content);
            message.setDataHandler(dh);
            message.setHeader("Content-Transfer-Encoding", "base64");
        }

        message.saveChanges();
        return message;
    }
    catch (Exception e) {
        throw new ConnectionException("Unable to construct mail message from SOAP message", e);
    }
}
 
开发者ID:cecid,项目名称:hermes,代码行数:54,代码来源:SOAPMailSender.java


注:本文中的javax.mail.BodyPart.getInputStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。