MimeBodyPart extends BodyPart implements MimePart { public void setDataHandler(DataHandler dh) throws MessagingException { this.dh = dh; cachedContent = null; MimeBodyPart.invalidateContentHeaders(this); } MimeBodyPart();  MimeBodyPart(InputStream is);  MimeBodyPart(InternetHeaders headers, byte[] content); int getSize(); int getLineCount(); String getContentType(); boolean isMimeType(String mimeType); String getDisposition(); void setDisposition(String disposition); String getEncoding(); String getContentID(); void setContentID(String cid); String getContentMD5(); void setContentMD5(String md5); String[] getContentLanguage(); void setContentLanguage(String[] languages); String getDescription(); void setDescription(String description); void setDescription(String description, String charset); String getFileName(); void setFileName(String filename); InputStream getInputStream(); InputStream getRawInputStream(); DataHandler getDataHandler(); Object getContent(); void setDataHandler(DataHandler dh); void setContent(Object o, String type); void setText(String text); void setText(String text, String charset); void setText(String text, String charset, String subtype); void setContent(Multipart mp); void attachFile(File file); void attachFile(String file); void attachFile(File file, String contentType, String encoding); void attachFile(String file, String contentType, String encoding); void saveFile(File file); void saveFile(String file); void writeTo(OutputStream os); String[] getHeader(String name); String getHeader(String name, String delimiter); void setHeader(String name, String value); void addHeader(String name, String value); void removeHeader(String name); Enumeration getAllHeaders(); Enumeration getMatchingHeaders(String[] names); Enumeration getNonMatchingHeaders(String[] names); void addHeaderLine(String line); Enumeration getAllHeaderLines(); Enumeration getMatchingHeaderLines(String[] names); Enumeration getNonMatchingHeaderLines(String[] names);  }
@Test public void testSetDataHandler() throws Exception { Session s = Session.getInstance(new Properties()); MimeMessage orig = createMessage(s); MimeMultipart omp = (MimeMultipart)orig.getContent(); MimeBodyPart obp = (MimeBodyPart)omp.getBodyPart(0); final DataHandler odh = obp.getDataHandler(); MimeMessage msg = new MimeMessage(s); MimeMultipart mp = new MimeMultipart(); MimeBodyPart mbp = new MimeBodyPart() { { dh = odh; } }; mp.addBodyPart(mbp); msg.setContent(mp); msg = new MimeMessage(msg); mp = (MimeMultipart)msg.getContent(); mbp = (MimeBodyPart)mp.getBodyPart(0); assertEquals("text/x-test", mbp.getContentType()); assertEquals("quoted-printable", mbp.getEncoding()); assertEquals("test part", getString(mbp.getInputStream())); }