1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 package javax.mail.internet;
21
22 import java.io.IOException;
23 import java.io.OutputStream;
24
25 import javax.mail.MessagingException;
26
27 /**
28 * @version $Rev: 467553 $ $Date: 2006-10-25 00:01:51 -0400 (Wed, 25 Oct 2006) $
29 */
30
31
32 public class PreencodedMimeBodyPart extends MimeBodyPart {
33 // the defined transfer encoding
34 private String transferEncoding;
35
36
37 /**
38 * Create a new body part with the specified MIME transfer encoding.
39 *
40 * @param encoding The content encoding.
41 */
42 public PreencodedMimeBodyPart(String encoding) {
43 transferEncoding = encoding;
44 }
45
46
47 /**
48 * Retieve the defined encoding for this body part.
49 *
50 * @return
51 * @exception MessagingException
52 */
53 public String getEncoding() throws MessagingException {
54 return transferEncoding;
55 }
56
57 /**
58 * Write the body part content to the stream without applying
59 * and additional encodings.
60 *
61 * @param out The target output stream.
62 *
63 * @exception IOException
64 * @exception MessagingException
65 */
66 public void writeTo(OutputStream out) throws IOException, MessagingException {
67 headers.writeTo(out, null);
68 // add the separater between the headers and the data portion.
69 out.write('\r');
70 out.write('\n');
71 // write this out without getting an encoding stream
72 getDataHandler().writeTo(out);
73 out.flush();
74 }
75
76
77 /**
78 * Override of update headers to ensure the transfer encoding
79 * is forced to the correct type.
80 *
81 * @exception MessagingException
82 */
83 protected void updateHeaders() throws MessagingException {
84 super.updateHeaders();
85 setHeader("Content-Transfer-Encoding", transferEncoding);
86 }
87 }
88