KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > mail > util > LineOutputStream


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21
22 /*
23  * @(#)LineOutputStream.java 1.7 05/08/29
24  *
25  * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved.
26  */

27
28 package com.sun.mail.util;
29
30 import java.io.*;
31 import javax.mail.MessagingException JavaDoc;
32
33 /**
34  * This class is to support writing out Strings as a sequence of bytes
35  * terminated by a CRLF sequence. The String must contain only US-ASCII
36  * characters.<p>
37  *
38  * The expected use is to write out RFC822 style headers to an output
39  * stream. <p>
40  *
41  * @author John Mani
42  */

43
44 public class LineOutputStream extends FilterOutputStream {
45     private static byte[] newline;
46
47     static {
48     newline = new byte[2];
49     newline[0] = (byte)'\r';
50     newline[1] = (byte)'\n';
51     }
52
53     public LineOutputStream(OutputStream out) {
54     super(out);
55     }
56
57     public void writeln(String JavaDoc s) throws MessagingException JavaDoc {
58     try {
59         byte[] bytes = ASCIIUtility.getBytes(s);
60         out.write(bytes);
61         out.write(newline);
62     } catch (Exception JavaDoc ex) {
63         throw new MessagingException JavaDoc("IOException", ex);
64     }
65     }
66
67     public void writeln() throws MessagingException JavaDoc {
68     try {
69         out.write(newline);
70     } catch (Exception JavaDoc ex) {
71         throw new MessagingException JavaDoc("IOException", ex);
72     }
73     }
74 }
75
Popular Tags