FileDocCategorySizeDatePackage
PreencodedMimeBodyPart.javaAPI DocJavaMail 1.4.34445Tue Nov 17 10:38:12 GMT 2009javax.mail.internet

PreencodedMimeBodyPart

public class PreencodedMimeBodyPart extends MimeBodyPart
A MimeBodyPart that handles data that has already been encoded. This class is useful when constructing a message and attaching data that has already been encoded (for example, using base64 encoding). The data may have been encoded by the application, or may have been stored in a file or database in encoded form. The encoding is supplied when this object is created. The data is attached to this object in the usual fashion, by using the setText, setContent, or setDataHandler methods.
since
JavaMail 1.4

Fields Summary
private String
encoding
Constructors Summary
public PreencodedMimeBodyPart(String encoding)
Create a PreencodedMimeBodyPart that assumes the data is encoded using the specified encoding. The encoding must be a MIME supported Content-Transfer-Encoding.

	this.encoding = encoding;
    
Methods Summary
public java.lang.StringgetEncoding()
Returns the content transfer encoding specified when this object was created.

	return encoding;
    
protected voidupdateHeaders()
Force the Content-Transfer-Encoding header to use the encoding that was specified when this object was created.

	super.updateHeaders();
	MimeBodyPart.setEncoding(this, encoding);
    
public voidwriteTo(java.io.OutputStream os)
Output the body part as an RFC 822 format stream.

exception
MessagingException
exception
IOException if an error occurs writing to the stream or if an error is generated by the javax.activation layer.
see
javax.activation.DataHandler#writeTo


	// see if we already have a LOS
	LineOutputStream los = null;
	if (os instanceof LineOutputStream) {
	    los = (LineOutputStream) os;
	} else {
	    los = new LineOutputStream(os);
	}

	// First, write out the header
	Enumeration hdrLines = getAllHeaderLines();
	while (hdrLines.hasMoreElements())
	    los.writeln((String)hdrLines.nextElement());

	// The CRLF separator between header and content
	los.writeln();

	// Finally, the content, already encoded.
	getDataHandler().writeTo(os);
	os.flush();