📄 mimebodypart.java
字号:
* absent. <p> * * This implementation uses <code>getHeader(name)</code> * to obtain the requisite header field. */ public String getContentID() throws MessagingException { return getHeader("Content-Id", null); } /** * Set the "Content-ID" header field of this body part. * If the <code>cid</code> parameter is null, any existing * "Content-ID" is removed. * * @exception IllegalWriteException if the underlying * implementation does not support modification * @exception IllegalStateException if this body part is * obtained from a READ_ONLY folder. * @exception MessagingException * @since JavaMail 1.3 */ public void setContentID(String cid) throws MessagingException { if (cid == null) removeHeader("Content-ID"); else setHeader("Content-ID", cid); } /** * Return the value of the "Content-MD5" header field. Returns * <code>null</code> if this field is unavailable or its value * is absent. <p> * * This implementation uses <code>getHeader(name)</code> * to obtain the requisite header field. */ public String getContentMD5() throws MessagingException { return getHeader("Content-MD5", null); } /** * Set the "Content-MD5" header field of this body part. * * @exception IllegalWriteException if the underlying * implementation does not support modification * @exception IllegalStateException if this body part is * obtained from a READ_ONLY folder. */ public void setContentMD5(String md5) throws MessagingException { setHeader("Content-MD5", md5); } /** * Get the languages specified in the Content-Language header * of this MimePart. The Content-Language header is defined by * RFC 1766. Returns <code>null</code> if this header is not * available or its value is absent. <p> * * This implementation uses <code>getHeader(name)</code> * to obtain the requisite header field. */ public String[] getContentLanguage() throws MessagingException { return getContentLanguage(this); } /** * Set the Content-Language header of this MimePart. The * Content-Language header is defined by RFC 1766. * * @param languages array of language tags */ public void setContentLanguage(String[] languages) throws MessagingException { setContentLanguage(this, languages); } /** * Returns the "Content-Description" header field of this body part. * This typically associates some descriptive information with * this part. Returns null if this field is unavailable or its * value is absent. <p> * * If the Content-Description field is encoded as per RFC 2047, * it is decoded and converted into Unicode. If the decoding or * conversion fails, the raw data is returned as is. <p> * * This implementation uses <code>getHeader(name)</code> * to obtain the requisite header field. * * @return content description */ public String getDescription() throws MessagingException { return getDescription(this); } /** * Set the "Content-Description" header field for this body part. * If the description parameter is <code>null</code>, then any * existing "Content-Description" fields are removed. <p> * * If the description contains non US-ASCII characters, it will * be encoded using the platform's default charset. If the * description contains only US-ASCII characters, no encoding * is done and it is used as is. <p> * * Note that if the charset encoding process fails, a * MessagingException is thrown, and an UnsupportedEncodingException * is included in the chain of nested exceptions within the * MessagingException. * * @param description content description * @exception IllegalWriteException if the underlying * implementation does not support modification * @exception IllegalStateException if this body part is * obtained from a READ_ONLY folder. * @exception MessagingException otherwise; an * UnsupportedEncodingException may be included * in the exception chain if the charset * conversion fails. */ public void setDescription(String description) throws MessagingException { setDescription(description, null); } /** * Set the "Content-Description" header field for this body part. * If the description parameter is <code>null</code>, then any * existing "Content-Description" fields are removed. <p> * * If the description contains non US-ASCII characters, it will * be encoded using the specified charset. If the description * contains only US-ASCII characters, no encoding is done and * it is used as is. <p> * * Note that if the charset encoding process fails, a * MessagingException is thrown, and an UnsupportedEncodingException * is included in the chain of nested exceptions within the * MessagingException. * * @param description Description * @param charset Charset for encoding * @exception IllegalWriteException if the underlying * implementation does not support modification * @exception IllegalStateException if this body part is * obtained from a READ_ONLY folder. * @exception MessagingException otherwise; an * UnsupportedEncodingException may be included * in the exception chain if the charset * conversion fails. */ public void setDescription(String description, String charset) throws MessagingException { setDescription(this, description, charset); } /** * Get the filename associated with this body part. <p> * * Returns the value of the "filename" parameter from the * "Content-Disposition" header field of this body part. If its * not available, returns the value of the "name" parameter from * the "Content-Type" header field of this body part. * Returns <code>null</code> if both are absent. <p> * * If the <code>mail.mime.encodefilename</code> System property * is set to true, the {@link MimeUtility#decodeText * MimeUtility.decodeText} method will be used to decode the * filename. While such encoding is not supported by the MIME * spec, many mailers use this technique to support non-ASCII * characters in filenames. The default value of this property * is false. * * @return filename */ public String getFileName() throws MessagingException { return getFileName(this); } /** * Set the filename associated with this body part, if possible. <p> * * Sets the "filename" parameter of the "Content-Disposition" * header field of this body part. For compatibility with older * mailers, the "name" parameter of the "Content-Type" header is * also set. <p> * * If the <code>mail.mime.encodefilename</code> System property * is set to true, the {@link MimeUtility#encodeText * MimeUtility.encodeText} method will be used to encode the * filename. While such encoding is not supported by the MIME * spec, many mailers use this technique to support non-ASCII * characters in filenames. The default value of this property * is false. * * @exception IllegalWriteException if the underlying * implementation does not support modification * @exception IllegalStateException if this body part is * obtained from a READ_ONLY folder. */ public void setFileName(String filename) throws MessagingException { setFileName(this, filename); } /** * Return a decoded input stream for this body part's "content". <p> * * This implementation obtains the input stream from the DataHandler. * That is, it invokes getDataHandler().getInputStream(); * * @return an InputStream * @exception MessagingException * @exception IOException this is typically thrown by the * DataHandler. Refer to the documentation for * javax.activation.DataHandler for more details. * * @see #getContentStream * @see javax.activation.DataHandler#getInputStream */ public InputStream getInputStream() throws IOException, MessagingException { return getDataHandler().getInputStream(); } /** * Produce the raw bytes of the content. This method is used * when creating a DataHandler object for the content. Subclasses * that can provide a separate input stream for just the Part * content might want to override this method. <p> * * @see #content * @see MimeMessage#getContentStream */ protected InputStream getContentStream() throws MessagingException { if (contentStream != null) return ((SharedInputStream)contentStream).newStream(0, -1); if (content != null) return new ByteArrayInputStream(content); throw new MessagingException("No content"); } /** * Return an InputStream to the raw data with any Content-Transfer-Encoding * intact. This method is useful if the "Content-Transfer-Encoding" * header is incorrect or corrupt, which would prevent the * <code>getInputStream</code> method or <code>getContent</code> method * from returning the correct data. In such a case the application may * use this method and attempt to decode the raw data itself. <p> * * This implementation simply calls the <code>getContentStream</code> * method. * * @see #getInputStream * @see #getContentStream * @since JavaMail 1.2 */ public InputStream getRawInputStream() throws MessagingException { return getContentStream(); } /** * Return a DataHandler for this body part's content. <p> * * The implementation provided here works just like the * the implementation in MimeMessage. * @see MimeMessage#getDataHandler */ public DataHandler getDataHandler() throws MessagingException { if (dh == null) dh = new DataHandler(new MimePartDataSource(this)); return dh; } /** * Return the content as a Java object. The type of the object * returned is of course dependent on the content itself. For * example, the native format of a text/plain content is usually * a String object. The native format for a "multipart" * content is always a Multipart subclass. For content types that are * unknown to the DataHandler system, an input stream is returned * as the content. <p> * * This implementation obtains the content from the DataHandler. * That is, it invokes getDataHandler().getContent(); * If the content is a Multipart or Message object and was created by * parsing a stream, the object is cached and returned in subsequent * calls so that modifications to the content will not be lost. * * @return Object * @exception MessagingException * @exception IOException this is typically thrown by the * DataHandler. Refer to the documentation for * javax.activation.DataHandler for more details. */ public Object getContent() throws IOException, MessagingException { if (cachedContent != null) return cachedContent; Object c; try { c = getDataHandler().getContent(); } catch (FolderClosedIOException fex) { throw new FolderClosedException(fex.getFolder(), fex.getMessage()); } catch (MessageRemovedIOException mex) { throw new MessageRemovedException(mex.getMessage()); } if (cacheMultipart && (c instanceof Multipart || c instanceof Message) && (content != null || contentStream != null)) { cachedContent = c; } return c; } /** * This method provides the mechanism to set this body part's content. * The given DataHandler object should wrap the actual content. * * @param dh The DataHandler for the content * @exception IllegalWriteException if the underlying * implementation does not support modification * @exception IllegalStateException if this body part is * obtained from a READ_ONLY folder. */ public void setDataHandler(DataHandler dh) throws MessagingException { this.dh = dh; cachedContent = null; MimeBodyPart.invalidateContentHeaders(this); } /** * A convenience method for setting this body part's content. <p> * * The content is wrapped in a DataHandler object. Note that a * DataContentHandler class for the specified type should be * available to the JavaMail implementation for this to work right. * That is, to do <code>setContent(foobar, "application/x-foobar")</code>, * a DataContentHandler for "application/x-foobar" should be installed. * Refer to the Java Activation Framework for more information. * * @param o the content object * @param type Mime type of the object * @exception IllegalWriteException if the underlying * implementation does not support modification of * existing values * @exception IllegalStateException if this body part is * obtained from a READ_ONLY folder. */ public void setContent(Object o, String type) throws MessagingException { if (o instanceof Multipart) { setContent((Multipart)o);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -