1 /*
2 * Copyright (C) The Apache Software Foundation. All rights reserved.
3 *
4 * This software is published under the terms of the Apache Software License
5 * version 1.1, a copy of which has been included with this distribution in
6 * the LICENSE file.
7 */
8 package org.apache.james.util;
9
10 import java.io.OutputStream;
11 import java.io.PrintWriter;
12 import java.io.Writer;
13
14 /***
15 * Writes to a wrapped Writer class, ensuring that all line separators are '\r\n', regardless
16 * of platform.
17 */
18 public class InternetPrintWriter
19 extends PrintWriter {
20
21 /***
22 * The line separator to use.
23 */
24 private static String lineSeparator = "\r\n";
25
26 /***
27 * Whether the Writer autoflushes on line feeds
28 */
29 private final boolean autoFlush;
30
31 /***
32 * Constructor that takes a writer to wrap.
33 *
34 * @param out the wrapped Writer
35 */
36 public InternetPrintWriter (Writer out) {
37 super (out);
38 autoFlush = false;
39 }
40
41 /***
42 * Constructor that takes a writer to wrap.
43 *
44 * @param out the wrapped Writer
45 * @param autoFlush whether to flush after each print call
46 */
47 public InternetPrintWriter (Writer out, boolean autoFlush) {
48 super (out, autoFlush);
49 this.autoFlush = autoFlush;
50 }
51
52 /***
53 * Constructor that takes a stream to wrap.
54 *
55 * @param out the wrapped OutputStream
56 */
57 public InternetPrintWriter (OutputStream out) {
58 super (out);
59 autoFlush = false;
60 }
61
62 /***
63 * Constructor that takes a stream to wrap.
64 *
65 * @param out the wrapped OutputStream
66 * @param autoFlush whether to flush after each print call
67 */
68 public InternetPrintWriter (OutputStream out, boolean autoFlush) {
69 super (out, autoFlush);
70 this.autoFlush = autoFlush;
71 }
72
73 /***
74 * Print a line separator.
75 */
76 public void println () {
77 synchronized (lock) {
78 write(lineSeparator);
79 if (autoFlush) {
80 flush();
81 }
82 }
83 }
84
85 /***
86 * Print a boolean followed by a line separator.
87 *
88 * @param x the boolean to print
89 */
90 public void println(boolean x) {
91 synchronized (lock) {
92 print(x);
93 println();
94 }
95 }
96
97 /***
98 * Print a char followed by a line separator.
99 *
100 * @param x the char to print
101 */
102 public void println(char x) {
103 synchronized (lock) {
104 print (x);
105 println ();
106 }
107 }
108
109 /***
110 * Print a int followed by a line separator.
111 *
112 * @param x the int to print
113 */
114 public void println (int x) {
115 synchronized (lock) {
116 print (x);
117 println ();
118 }
119 }
120
121 /***
122 * Print a long followed by a line separator.
123 *
124 * @param x the long to print
125 */
126 public void println (long x) {
127 synchronized (lock) {
128 print (x);
129 println ();
130 }
131 }
132
133 /***
134 * Print a float followed by a line separator.
135 *
136 * @param x the float to print
137 */
138 public void println (float x) {
139 synchronized (lock) {
140 print (x);
141 println ();
142 }
143 }
144
145 /***
146 * Print a double followed by a line separator.
147 *
148 * @param x the double to print
149 */
150 public void println (double x) {
151 synchronized (lock) {
152 print (x);
153 println ();
154 }
155 }
156
157 /***
158 * Print a character array followed by a line separator.
159 *
160 * @param x the character array to print
161 */
162 public void println (char[] x) {
163 synchronized (lock) {
164 print (x);
165 println ();
166 }
167 }
168
169 /***
170 * Print a String followed by a line separator.
171 *
172 * @param x the String to print
173 */
174 public void println (String x) {
175 synchronized (lock) {
176 print (x);
177 println ();
178 }
179 }
180
181 /***
182 * Print an Object followed by a line separator.
183 *
184 * @param x the Object to print
185 */
186 public void println (Object x) {
187 synchronized (lock) {
188 print (x);
189 println ();
190 }
191 }
192 }
This page was automatically generated by Maven