author | bpb |
Wed, 17 Jul 2019 14:24:24 -0700 | |
changeset 55727 | 070ffafc4294 |
parent 53148 | 17d568776429 |
child 58027 | 930551e8ac62 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
55727 | 2 |
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.io; |
|
27 |
||
28 |
import java.util.Formatter; |
|
29 |
import java.util.Locale; |
|
7966
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
30 |
import java.nio.charset.Charset; |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
31 |
import java.nio.charset.IllegalCharsetNameException; |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
32 |
import java.nio.charset.UnsupportedCharsetException; |
2 | 33 |
|
34 |
/** |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
35 |
* A {@code PrintStream} adds functionality to another output stream, |
2 | 36 |
* namely the ability to print representations of various data values |
37 |
* conveniently. Two other features are provided as well. Unlike other output |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
38 |
* streams, a {@code PrintStream} never throws an |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
39 |
* {@code IOException}; instead, exceptional situations merely set an |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
40 |
* internal flag that can be tested via the {@code checkError} method. |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
41 |
* Optionally, a {@code PrintStream} can be created so as to flush |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
42 |
* automatically; this means that the {@code flush} method is |
2 | 43 |
* automatically invoked after a byte array is written, one of the |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
44 |
* {@code println} methods is invoked, or a newline character or byte |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
45 |
* ({@code '\n'}) is written. |
2 | 46 |
* |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
47 |
* <p> All characters printed by a {@code PrintStream} are converted into |
55727 | 48 |
* bytes using the given encoding or charset, or the platform's default |
49 |
* character encoding if not specified. |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
50 |
* The {@link PrintWriter} class should be used in situations that require |
55727 | 51 |
* writing characters rather than bytes. |
2 | 52 |
* |
48252
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
53 |
* <p> This class always replaces malformed and unmappable character sequences with |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
54 |
* the charset's default replacement string. |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
55 |
* The {@linkplain java.nio.charset.CharsetEncoder} class should be used when more |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
56 |
* control over the encoding process is required. |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
57 |
* |
2 | 58 |
* @author Frank Yellin |
59 |
* @author Mark Reinhold |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
23010
diff
changeset
|
60 |
* @since 1.0 |
2 | 61 |
*/ |
62 |
||
63 |
public class PrintStream extends FilterOutputStream |
|
64 |
implements Appendable, Closeable |
|
65 |
{ |
|
66 |
||
7966
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
67 |
private final boolean autoFlush; |
2 | 68 |
private boolean trouble = false; |
69 |
private Formatter formatter; |
|
70 |
||
71 |
/** |
|
72 |
* Track both the text- and character-output streams, so that their buffers |
|
73 |
* can be flushed without flushing the entire stream. |
|
74 |
*/ |
|
75 |
private BufferedWriter textOut; |
|
76 |
private OutputStreamWriter charOut; |
|
77 |
||
78 |
/** |
|
8166
13423c0952ad
7012540: java.util.Objects.nonNull() incorrectly named
briangoetz
parents:
7982
diff
changeset
|
79 |
* requireNonNull is explicitly declared here so as not to create an extra |
13423c0952ad
7012540: java.util.Objects.nonNull() incorrectly named
briangoetz
parents:
7982
diff
changeset
|
80 |
* dependency on java.util.Objects.requireNonNull. PrintStream is loaded |
7966
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
81 |
* early during system initialization. |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
82 |
*/ |
8166
13423c0952ad
7012540: java.util.Objects.nonNull() incorrectly named
briangoetz
parents:
7982
diff
changeset
|
83 |
private static <T> T requireNonNull(T obj, String message) { |
7966
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
84 |
if (obj == null) |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
85 |
throw new NullPointerException(message); |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
86 |
return obj; |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
87 |
} |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
88 |
|
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
89 |
/** |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
90 |
* Returns a charset object for the given charset name. |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
91 |
* @throws NullPointerException is csn is null |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
92 |
* @throws UnsupportedEncodingException if the charset is not supported |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
93 |
*/ |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
94 |
private static Charset toCharset(String csn) |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
95 |
throws UnsupportedEncodingException |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
96 |
{ |
8166
13423c0952ad
7012540: java.util.Objects.nonNull() incorrectly named
briangoetz
parents:
7982
diff
changeset
|
97 |
requireNonNull(csn, "charsetName"); |
7966
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
98 |
try { |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
99 |
return Charset.forName(csn); |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
100 |
} catch (IllegalCharsetNameException|UnsupportedCharsetException unused) { |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
101 |
// UnsupportedEncodingException should be thrown |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
102 |
throw new UnsupportedEncodingException(csn); |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
103 |
} |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
104 |
} |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
105 |
|
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
106 |
/* Private constructors */ |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
107 |
private PrintStream(boolean autoFlush, OutputStream out) { |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
108 |
super(out); |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
109 |
this.autoFlush = autoFlush; |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
110 |
this.charOut = new OutputStreamWriter(this); |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
111 |
this.textOut = new BufferedWriter(charOut); |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
112 |
} |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
113 |
|
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
114 |
/* Variant of the private constructor so that the given charset name |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
115 |
* can be verified before evaluating the OutputStream argument. Used |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
116 |
* by constructors creating a FileOutputStream that also take a |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
117 |
* charset name. |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
118 |
*/ |
48252
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
119 |
private PrintStream(boolean autoFlush, Charset charset, OutputStream out) { |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
120 |
this(out, autoFlush, charset); |
7966
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
121 |
} |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
122 |
|
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
123 |
/** |
55727 | 124 |
* Creates a new print stream, without automatic line flushing, with the |
125 |
* specified OutputStream. Characters written to the stream are converted |
|
126 |
* to bytes using the platform's default character encoding. |
|
2 | 127 |
* |
128 |
* @param out The output stream to which values and objects will be |
|
129 |
* printed |
|
130 |
* |
|
131 |
* @see java.io.PrintWriter#PrintWriter(java.io.OutputStream) |
|
132 |
*/ |
|
133 |
public PrintStream(OutputStream out) { |
|
134 |
this(out, false); |
|
135 |
} |
|
136 |
||
137 |
/** |
|
55727 | 138 |
* Creates a new print stream, with the specified OutputStream and line |
139 |
* flushing. Characters written to the stream are converted to bytes using |
|
140 |
* the platform's default character encoding. |
|
2 | 141 |
* |
142 |
* @param out The output stream to which values and objects will be |
|
143 |
* printed |
|
55727 | 144 |
* @param autoFlush Whether the output buffer will be flushed |
2 | 145 |
* whenever a byte array is written, one of the |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
146 |
* {@code println} methods is invoked, or a newline |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
147 |
* character or byte ({@code '\n'}) is written |
2 | 148 |
* |
149 |
* @see java.io.PrintWriter#PrintWriter(java.io.OutputStream, boolean) |
|
150 |
*/ |
|
151 |
public PrintStream(OutputStream out, boolean autoFlush) { |
|
8166
13423c0952ad
7012540: java.util.Objects.nonNull() incorrectly named
briangoetz
parents:
7982
diff
changeset
|
152 |
this(autoFlush, requireNonNull(out, "Null output stream")); |
2 | 153 |
} |
154 |
||
155 |
/** |
|
55727 | 156 |
* Creates a new print stream, with the specified OutputStream, line |
157 |
* flushing, and character encoding. |
|
2 | 158 |
* |
159 |
* @param out The output stream to which values and objects will be |
|
160 |
* printed |
|
55727 | 161 |
* @param autoFlush Whether the output buffer will be flushed |
2 | 162 |
* whenever a byte array is written, one of the |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
163 |
* {@code println} methods is invoked, or a newline |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
164 |
* character or byte ({@code '\n'}) is written |
2 | 165 |
* @param encoding The name of a supported |
166 |
* <a href="../lang/package-summary.html#charenc"> |
|
167 |
* character encoding</a> |
|
168 |
* |
|
169 |
* @throws UnsupportedEncodingException |
|
170 |
* If the named encoding is not supported |
|
171 |
* |
|
172 |
* @since 1.4 |
|
173 |
*/ |
|
174 |
public PrintStream(OutputStream out, boolean autoFlush, String encoding) |
|
175 |
throws UnsupportedEncodingException |
|
176 |
{ |
|
48252
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
177 |
this(requireNonNull(out, "Null output stream"), autoFlush, toCharset(encoding)); |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
178 |
} |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
179 |
|
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
180 |
/** |
55727 | 181 |
* Creates a new print stream, with the specified OutputStream, line |
48252
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
182 |
* flushing and charset. This convenience constructor creates the necessary |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
183 |
* intermediate {@link java.io.OutputStreamWriter OutputStreamWriter}, |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
184 |
* which will encode characters using the provided charset. |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
185 |
* |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
186 |
* @param out The output stream to which values and objects will be |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
187 |
* printed |
55727 | 188 |
* @param autoFlush Whether the output buffer will be flushed |
48252
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
189 |
* whenever a byte array is written, one of the |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
190 |
* {@code println} methods is invoked, or a newline |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
191 |
* character or byte ({@code '\n'}) is written |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
192 |
* @param charset A {@linkplain java.nio.charset.Charset charset} |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
193 |
* |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
194 |
* @since 10 |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
195 |
*/ |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
196 |
public PrintStream(OutputStream out, boolean autoFlush, Charset charset) { |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
197 |
super(out); |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
198 |
this.autoFlush = autoFlush; |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
199 |
this.charOut = new OutputStreamWriter(this, charset); |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
200 |
this.textOut = new BufferedWriter(charOut); |
2 | 201 |
} |
202 |
||
203 |
/** |
|
204 |
* Creates a new print stream, without automatic line flushing, with the |
|
205 |
* specified file name. This convenience constructor creates |
|
206 |
* the necessary intermediate {@link java.io.OutputStreamWriter |
|
207 |
* OutputStreamWriter}, which will encode characters using the |
|
208 |
* {@linkplain java.nio.charset.Charset#defaultCharset() default charset} |
|
209 |
* for this instance of the Java virtual machine. |
|
210 |
* |
|
211 |
* @param fileName |
|
212 |
* The name of the file to use as the destination of this print |
|
213 |
* stream. If the file exists, then it will be truncated to |
|
214 |
* zero size; otherwise, a new file will be created. The output |
|
215 |
* will be written to the file and is buffered. |
|
216 |
* |
|
217 |
* @throws FileNotFoundException |
|
218 |
* If the given file object does not denote an existing, writable |
|
219 |
* regular file and a new regular file of that name cannot be |
|
220 |
* created, or if some other error occurs while opening or |
|
221 |
* creating the file |
|
222 |
* |
|
223 |
* @throws SecurityException |
|
224 |
* If a security manager is present and {@link |
|
225 |
* SecurityManager#checkWrite checkWrite(fileName)} denies write |
|
226 |
* access to the file |
|
227 |
* |
|
228 |
* @since 1.5 |
|
229 |
*/ |
|
230 |
public PrintStream(String fileName) throws FileNotFoundException { |
|
231 |
this(false, new FileOutputStream(fileName)); |
|
232 |
} |
|
233 |
||
234 |
/** |
|
235 |
* Creates a new print stream, without automatic line flushing, with the |
|
236 |
* specified file name and charset. This convenience constructor creates |
|
237 |
* the necessary intermediate {@link java.io.OutputStreamWriter |
|
238 |
* OutputStreamWriter}, which will encode characters using the provided |
|
239 |
* charset. |
|
240 |
* |
|
241 |
* @param fileName |
|
242 |
* The name of the file to use as the destination of this print |
|
243 |
* stream. If the file exists, then it will be truncated to |
|
244 |
* zero size; otherwise, a new file will be created. The output |
|
245 |
* will be written to the file and is buffered. |
|
246 |
* |
|
247 |
* @param csn |
|
248 |
* The name of a supported {@linkplain java.nio.charset.Charset |
|
249 |
* charset} |
|
250 |
* |
|
251 |
* @throws FileNotFoundException |
|
252 |
* If the given file object does not denote an existing, writable |
|
253 |
* regular file and a new regular file of that name cannot be |
|
254 |
* created, or if some other error occurs while opening or |
|
255 |
* creating the file |
|
256 |
* |
|
257 |
* @throws SecurityException |
|
258 |
* If a security manager is present and {@link |
|
259 |
* SecurityManager#checkWrite checkWrite(fileName)} denies write |
|
260 |
* access to the file |
|
261 |
* |
|
262 |
* @throws UnsupportedEncodingException |
|
263 |
* If the named charset is not supported |
|
264 |
* |
|
265 |
* @since 1.5 |
|
266 |
*/ |
|
267 |
public PrintStream(String fileName, String csn) |
|
268 |
throws FileNotFoundException, UnsupportedEncodingException |
|
269 |
{ |
|
7966
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
270 |
// ensure charset is checked before the file is opened |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
271 |
this(false, toCharset(csn), new FileOutputStream(fileName)); |
2 | 272 |
} |
273 |
||
274 |
/** |
|
275 |
* Creates a new print stream, without automatic line flushing, with the |
|
48252
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
276 |
* specified file name and charset. This convenience constructor creates |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
277 |
* the necessary intermediate {@link java.io.OutputStreamWriter |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
278 |
* OutputStreamWriter}, which will encode characters using the provided |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
279 |
* charset. |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
280 |
* |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
281 |
* @param fileName |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
282 |
* The name of the file to use as the destination of this print |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
283 |
* stream. If the file exists, then it will be truncated to |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
284 |
* zero size; otherwise, a new file will be created. The output |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
285 |
* will be written to the file and is buffered. |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
286 |
* |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
287 |
* @param charset |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
288 |
* A {@linkplain java.nio.charset.Charset charset} |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
289 |
* |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
290 |
* @throws IOException |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
291 |
* if an I/O error occurs while opening or creating the file |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
292 |
* |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
293 |
* @throws SecurityException |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
294 |
* If a security manager is present and {@link |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
295 |
* SecurityManager#checkWrite checkWrite(fileName)} denies write |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
296 |
* access to the file |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
297 |
* |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
298 |
* @since 10 |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
299 |
*/ |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
300 |
public PrintStream(String fileName, Charset charset) throws IOException { |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
301 |
this(false, requireNonNull(charset, "charset"), new FileOutputStream(fileName)); |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
302 |
} |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
303 |
|
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
304 |
/** |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
305 |
* Creates a new print stream, without automatic line flushing, with the |
2 | 306 |
* specified file. This convenience constructor creates the necessary |
307 |
* intermediate {@link java.io.OutputStreamWriter OutputStreamWriter}, |
|
308 |
* which will encode characters using the {@linkplain |
|
309 |
* java.nio.charset.Charset#defaultCharset() default charset} for this |
|
310 |
* instance of the Java virtual machine. |
|
311 |
* |
|
312 |
* @param file |
|
313 |
* The file to use as the destination of this print stream. If the |
|
314 |
* file exists, then it will be truncated to zero size; otherwise, |
|
315 |
* a new file will be created. The output will be written to the |
|
316 |
* file and is buffered. |
|
317 |
* |
|
318 |
* @throws FileNotFoundException |
|
319 |
* If the given file object does not denote an existing, writable |
|
320 |
* regular file and a new regular file of that name cannot be |
|
321 |
* created, or if some other error occurs while opening or |
|
322 |
* creating the file |
|
323 |
* |
|
324 |
* @throws SecurityException |
|
325 |
* If a security manager is present and {@link |
|
326 |
* SecurityManager#checkWrite checkWrite(file.getPath())} |
|
327 |
* denies write access to the file |
|
328 |
* |
|
329 |
* @since 1.5 |
|
330 |
*/ |
|
331 |
public PrintStream(File file) throws FileNotFoundException { |
|
332 |
this(false, new FileOutputStream(file)); |
|
333 |
} |
|
334 |
||
335 |
/** |
|
336 |
* Creates a new print stream, without automatic line flushing, with the |
|
337 |
* specified file and charset. This convenience constructor creates |
|
338 |
* the necessary intermediate {@link java.io.OutputStreamWriter |
|
339 |
* OutputStreamWriter}, which will encode characters using the provided |
|
340 |
* charset. |
|
341 |
* |
|
342 |
* @param file |
|
343 |
* The file to use as the destination of this print stream. If the |
|
344 |
* file exists, then it will be truncated to zero size; otherwise, |
|
345 |
* a new file will be created. The output will be written to the |
|
346 |
* file and is buffered. |
|
347 |
* |
|
348 |
* @param csn |
|
349 |
* The name of a supported {@linkplain java.nio.charset.Charset |
|
350 |
* charset} |
|
351 |
* |
|
352 |
* @throws FileNotFoundException |
|
353 |
* If the given file object does not denote an existing, writable |
|
354 |
* regular file and a new regular file of that name cannot be |
|
355 |
* created, or if some other error occurs while opening or |
|
356 |
* creating the file |
|
357 |
* |
|
358 |
* @throws SecurityException |
|
21278 | 359 |
* If a security manager is present and {@link |
2 | 360 |
* SecurityManager#checkWrite checkWrite(file.getPath())} |
361 |
* denies write access to the file |
|
362 |
* |
|
363 |
* @throws UnsupportedEncodingException |
|
364 |
* If the named charset is not supported |
|
365 |
* |
|
366 |
* @since 1.5 |
|
367 |
*/ |
|
368 |
public PrintStream(File file, String csn) |
|
369 |
throws FileNotFoundException, UnsupportedEncodingException |
|
370 |
{ |
|
7966
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
371 |
// ensure charset is checked before the file is opened |
a23e3f47c5a8
7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents:
5506
diff
changeset
|
372 |
this(false, toCharset(csn), new FileOutputStream(file)); |
2 | 373 |
} |
374 |
||
48252
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
375 |
|
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
376 |
/** |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
377 |
* Creates a new print stream, without automatic line flushing, with the |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
378 |
* specified file and charset. This convenience constructor creates |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
379 |
* the necessary intermediate {@link java.io.OutputStreamWriter |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
380 |
* OutputStreamWriter}, which will encode characters using the provided |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
381 |
* charset. |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
382 |
* |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
383 |
* @param file |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
384 |
* The file to use as the destination of this print stream. If the |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
385 |
* file exists, then it will be truncated to zero size; otherwise, |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
386 |
* a new file will be created. The output will be written to the |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
387 |
* file and is buffered. |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
388 |
* |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
389 |
* @param charset |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
390 |
* A {@linkplain java.nio.charset.Charset charset} |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
391 |
* |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
392 |
* @throws IOException |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
393 |
* if an I/O error occurs while opening or creating the file |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
394 |
* |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
395 |
* @throws SecurityException |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
396 |
* If a security manager is present and {@link |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
397 |
* SecurityManager#checkWrite checkWrite(file.getPath())} |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
398 |
* denies write access to the file |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
399 |
* |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
400 |
* @since 10 |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
401 |
*/ |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
402 |
public PrintStream(File file, Charset charset) throws IOException { |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
403 |
this(false, requireNonNull(charset, "charset"), new FileOutputStream(file)); |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
404 |
} |
77b88d8f8380
8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents:
47216
diff
changeset
|
405 |
|
2 | 406 |
/** Check to make sure that the stream has not been closed */ |
407 |
private void ensureOpen() throws IOException { |
|
408 |
if (out == null) |
|
409 |
throw new IOException("Stream closed"); |
|
410 |
} |
|
411 |
||
412 |
/** |
|
413 |
* Flushes the stream. This is done by writing any buffered output bytes to |
|
414 |
* the underlying output stream and then flushing that stream. |
|
415 |
* |
|
416 |
* @see java.io.OutputStream#flush() |
|
417 |
*/ |
|
418 |
public void flush() { |
|
419 |
synchronized (this) { |
|
420 |
try { |
|
421 |
ensureOpen(); |
|
422 |
out.flush(); |
|
423 |
} |
|
424 |
catch (IOException x) { |
|
425 |
trouble = true; |
|
426 |
} |
|
427 |
} |
|
428 |
} |
|
429 |
||
430 |
private boolean closing = false; /* To avoid recursive closing */ |
|
431 |
||
432 |
/** |
|
433 |
* Closes the stream. This is done by flushing the stream and then closing |
|
434 |
* the underlying output stream. |
|
435 |
* |
|
436 |
* @see java.io.OutputStream#close() |
|
437 |
*/ |
|
438 |
public void close() { |
|
439 |
synchronized (this) { |
|
440 |
if (! closing) { |
|
441 |
closing = true; |
|
442 |
try { |
|
443 |
textOut.close(); |
|
444 |
out.close(); |
|
445 |
} |
|
446 |
catch (IOException x) { |
|
447 |
trouble = true; |
|
448 |
} |
|
449 |
textOut = null; |
|
450 |
charOut = null; |
|
451 |
out = null; |
|
452 |
} |
|
453 |
} |
|
454 |
} |
|
455 |
||
456 |
/** |
|
457 |
* Flushes the stream and checks its error state. The internal error state |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
458 |
* is set to {@code true} when the underlying output stream throws an |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
459 |
* {@code IOException} other than {@code InterruptedIOException}, |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
460 |
* and when the {@code setError} method is invoked. If an operation |
2 | 461 |
* on the underlying output stream throws an |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
462 |
* {@code InterruptedIOException}, then the {@code PrintStream} |
2 | 463 |
* converts the exception back into an interrupt by doing: |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
464 |
* <pre>{@code |
2 | 465 |
* Thread.currentThread().interrupt(); |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
466 |
* }</pre> |
2 | 467 |
* or the equivalent. |
468 |
* |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
469 |
* @return {@code true} if and only if this stream has encountered an |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
470 |
* {@code IOException} other than |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
471 |
* {@code InterruptedIOException}, or the |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
472 |
* {@code setError} method has been invoked |
2 | 473 |
*/ |
474 |
public boolean checkError() { |
|
475 |
if (out != null) |
|
476 |
flush(); |
|
477 |
if (out instanceof java.io.PrintStream) { |
|
478 |
PrintStream ps = (PrintStream) out; |
|
479 |
return ps.checkError(); |
|
480 |
} |
|
481 |
return trouble; |
|
482 |
} |
|
483 |
||
484 |
/** |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
485 |
* Sets the error state of the stream to {@code true}. |
2 | 486 |
* |
487 |
* <p> This method will cause subsequent invocations of {@link |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
488 |
* #checkError()} to return {@code true} until |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
489 |
* {@link #clearError()} is invoked. |
2 | 490 |
* |
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
23010
diff
changeset
|
491 |
* @since 1.1 |
2 | 492 |
*/ |
493 |
protected void setError() { |
|
494 |
trouble = true; |
|
495 |
} |
|
496 |
||
497 |
/** |
|
498 |
* Clears the internal error state of this stream. |
|
499 |
* |
|
500 |
* <p> This method will cause subsequent invocations of {@link |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
501 |
* #checkError()} to return {@code false} until another write |
2 | 502 |
* operation fails and invokes {@link #setError()}. |
503 |
* |
|
504 |
* @since 1.6 |
|
505 |
*/ |
|
506 |
protected void clearError() { |
|
507 |
trouble = false; |
|
508 |
} |
|
509 |
||
510 |
/* |
|
511 |
* Exception-catching, synchronized output operations, |
|
512 |
* which also implement the write() methods of OutputStream |
|
513 |
*/ |
|
514 |
||
515 |
/** |
|
516 |
* Writes the specified byte to this stream. If the byte is a newline and |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
517 |
* automatic flushing is enabled then the {@code flush} method will be |
2 | 518 |
* invoked. |
519 |
* |
|
520 |
* <p> Note that the byte is written as given; to write a character that |
|
521 |
* will be translated according to the platform's default character |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
522 |
* encoding, use the {@code print(char)} or {@code println(char)} |
2 | 523 |
* methods. |
524 |
* |
|
525 |
* @param b The byte to be written |
|
526 |
* @see #print(char) |
|
527 |
* @see #println(char) |
|
528 |
*/ |
|
529 |
public void write(int b) { |
|
530 |
try { |
|
531 |
synchronized (this) { |
|
532 |
ensureOpen(); |
|
533 |
out.write(b); |
|
534 |
if ((b == '\n') && autoFlush) |
|
535 |
out.flush(); |
|
536 |
} |
|
537 |
} |
|
538 |
catch (InterruptedIOException x) { |
|
539 |
Thread.currentThread().interrupt(); |
|
540 |
} |
|
541 |
catch (IOException x) { |
|
542 |
trouble = true; |
|
543 |
} |
|
544 |
} |
|
545 |
||
546 |
/** |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
547 |
* Writes {@code len} bytes from the specified byte array starting at |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
548 |
* offset {@code off} to this stream. If automatic flushing is |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
549 |
* enabled then the {@code flush} method will be invoked. |
2 | 550 |
* |
551 |
* <p> Note that the bytes will be written as given; to write characters |
|
552 |
* that will be translated according to the platform's default character |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
553 |
* encoding, use the {@code print(char)} or {@code println(char)} |
2 | 554 |
* methods. |
555 |
* |
|
556 |
* @param buf A byte array |
|
557 |
* @param off Offset from which to start taking bytes |
|
558 |
* @param len Number of bytes to write |
|
559 |
*/ |
|
560 |
public void write(byte buf[], int off, int len) { |
|
561 |
try { |
|
562 |
synchronized (this) { |
|
563 |
ensureOpen(); |
|
564 |
out.write(buf, off, len); |
|
565 |
if (autoFlush) |
|
566 |
out.flush(); |
|
567 |
} |
|
568 |
} |
|
569 |
catch (InterruptedIOException x) { |
|
570 |
Thread.currentThread().interrupt(); |
|
571 |
} |
|
572 |
catch (IOException x) { |
|
573 |
trouble = true; |
|
574 |
} |
|
575 |
} |
|
576 |
||
577 |
/* |
|
578 |
* The following private methods on the text- and character-output streams |
|
579 |
* always flush the stream buffers, so that writes to the underlying byte |
|
580 |
* stream occur as promptly as with the original PrintStream. |
|
581 |
*/ |
|
582 |
||
53148 | 583 |
private void write(char[] buf) { |
2 | 584 |
try { |
585 |
synchronized (this) { |
|
586 |
ensureOpen(); |
|
587 |
textOut.write(buf); |
|
588 |
textOut.flushBuffer(); |
|
589 |
charOut.flushBuffer(); |
|
590 |
if (autoFlush) { |
|
591 |
for (int i = 0; i < buf.length; i++) |
|
53148 | 592 |
if (buf[i] == '\n') { |
2 | 593 |
out.flush(); |
53148 | 594 |
break; |
595 |
} |
|
2 | 596 |
} |
597 |
} |
|
53148 | 598 |
} catch (InterruptedIOException x) { |
599 |
Thread.currentThread().interrupt(); |
|
600 |
} catch (IOException x) { |
|
601 |
trouble = true; |
|
602 |
} |
|
603 |
} |
|
604 |
||
605 |
// Used to optimize away back-to-back flushing and synchronization when |
|
606 |
// using println, but since subclasses could exist which depend on |
|
607 |
// observing a call to print followed by newLine() we only use this if |
|
608 |
// getClass() == PrintStream.class to avoid compatibility issues. |
|
609 |
private void writeln(char[] buf) { |
|
610 |
try { |
|
611 |
synchronized (this) { |
|
612 |
ensureOpen(); |
|
613 |
textOut.write(buf); |
|
614 |
textOut.newLine(); |
|
615 |
textOut.flushBuffer(); |
|
616 |
charOut.flushBuffer(); |
|
617 |
if (autoFlush) |
|
618 |
out.flush(); |
|
619 |
} |
|
2 | 620 |
} |
621 |
catch (InterruptedIOException x) { |
|
622 |
Thread.currentThread().interrupt(); |
|
623 |
} |
|
624 |
catch (IOException x) { |
|
625 |
trouble = true; |
|
626 |
} |
|
627 |
} |
|
628 |
||
629 |
private void write(String s) { |
|
630 |
try { |
|
631 |
synchronized (this) { |
|
632 |
ensureOpen(); |
|
633 |
textOut.write(s); |
|
634 |
textOut.flushBuffer(); |
|
635 |
charOut.flushBuffer(); |
|
636 |
if (autoFlush && (s.indexOf('\n') >= 0)) |
|
637 |
out.flush(); |
|
638 |
} |
|
639 |
} |
|
640 |
catch (InterruptedIOException x) { |
|
641 |
Thread.currentThread().interrupt(); |
|
642 |
} |
|
643 |
catch (IOException x) { |
|
644 |
trouble = true; |
|
645 |
} |
|
646 |
} |
|
647 |
||
53148 | 648 |
// Used to optimize away back-to-back flushing and synchronization when |
649 |
// using println, but since subclasses could exist which depend on |
|
650 |
// observing a call to print followed by newLine we only use this if |
|
651 |
// getClass() == PrintStream.class to avoid compatibility issues. |
|
652 |
private void writeln(String s) { |
|
653 |
try { |
|
654 |
synchronized (this) { |
|
655 |
ensureOpen(); |
|
656 |
textOut.write(s); |
|
657 |
textOut.newLine(); |
|
658 |
textOut.flushBuffer(); |
|
659 |
charOut.flushBuffer(); |
|
660 |
if (autoFlush) |
|
661 |
out.flush(); |
|
662 |
} |
|
663 |
} |
|
664 |
catch (InterruptedIOException x) { |
|
665 |
Thread.currentThread().interrupt(); |
|
666 |
} |
|
667 |
catch (IOException x) { |
|
668 |
trouble = true; |
|
669 |
} |
|
670 |
} |
|
671 |
||
2 | 672 |
private void newLine() { |
673 |
try { |
|
674 |
synchronized (this) { |
|
675 |
ensureOpen(); |
|
676 |
textOut.newLine(); |
|
677 |
textOut.flushBuffer(); |
|
678 |
charOut.flushBuffer(); |
|
679 |
if (autoFlush) |
|
680 |
out.flush(); |
|
681 |
} |
|
682 |
} |
|
683 |
catch (InterruptedIOException x) { |
|
684 |
Thread.currentThread().interrupt(); |
|
685 |
} |
|
686 |
catch (IOException x) { |
|
687 |
trouble = true; |
|
688 |
} |
|
689 |
} |
|
690 |
||
691 |
/* Methods that do not terminate lines */ |
|
692 |
||
693 |
/** |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
694 |
* Prints a boolean value. The string produced by {@link |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
695 |
* java.lang.String#valueOf(boolean)} is translated into bytes |
2 | 696 |
* according to the platform's default character encoding, and these bytes |
697 |
* are written in exactly the manner of the |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
698 |
* {@link #write(int)} method. |
2 | 699 |
* |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
700 |
* @param b The {@code boolean} to be printed |
2 | 701 |
*/ |
702 |
public void print(boolean b) { |
|
40410 | 703 |
write(String.valueOf(b)); |
2 | 704 |
} |
705 |
||
706 |
/** |
|
707 |
* Prints a character. The character is translated into one or more bytes |
|
55727 | 708 |
* according to the character encoding given to the constructor, or the |
709 |
* platform's default character encoding if none specified. These bytes |
|
710 |
* are written in exactly the manner of the {@link #write(int)} method. |
|
2 | 711 |
* |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
712 |
* @param c The {@code char} to be printed |
2 | 713 |
*/ |
714 |
public void print(char c) { |
|
715 |
write(String.valueOf(c)); |
|
716 |
} |
|
717 |
||
718 |
/** |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
719 |
* Prints an integer. The string produced by {@link |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
720 |
* java.lang.String#valueOf(int)} is translated into bytes |
2 | 721 |
* according to the platform's default character encoding, and these bytes |
722 |
* are written in exactly the manner of the |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
723 |
* {@link #write(int)} method. |
2 | 724 |
* |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
725 |
* @param i The {@code int} to be printed |
2 | 726 |
* @see java.lang.Integer#toString(int) |
727 |
*/ |
|
728 |
public void print(int i) { |
|
729 |
write(String.valueOf(i)); |
|
730 |
} |
|
731 |
||
732 |
/** |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
733 |
* Prints a long integer. The string produced by {@link |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
734 |
* java.lang.String#valueOf(long)} is translated into bytes |
2 | 735 |
* according to the platform's default character encoding, and these bytes |
736 |
* are written in exactly the manner of the |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
737 |
* {@link #write(int)} method. |
2 | 738 |
* |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
739 |
* @param l The {@code long} to be printed |
2 | 740 |
* @see java.lang.Long#toString(long) |
741 |
*/ |
|
742 |
public void print(long l) { |
|
743 |
write(String.valueOf(l)); |
|
744 |
} |
|
745 |
||
746 |
/** |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
747 |
* Prints a floating-point number. The string produced by {@link |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
748 |
* java.lang.String#valueOf(float)} is translated into bytes |
2 | 749 |
* according to the platform's default character encoding, and these bytes |
750 |
* are written in exactly the manner of the |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
751 |
* {@link #write(int)} method. |
2 | 752 |
* |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
753 |
* @param f The {@code float} to be printed |
2 | 754 |
* @see java.lang.Float#toString(float) |
755 |
*/ |
|
756 |
public void print(float f) { |
|
757 |
write(String.valueOf(f)); |
|
758 |
} |
|
759 |
||
760 |
/** |
|
761 |
* Prints a double-precision floating-point number. The string produced by |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
762 |
* {@link java.lang.String#valueOf(double)} is translated into |
2 | 763 |
* bytes according to the platform's default character encoding, and these |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
764 |
* bytes are written in exactly the manner of the {@link |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
765 |
* #write(int)} method. |
2 | 766 |
* |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
767 |
* @param d The {@code double} to be printed |
2 | 768 |
* @see java.lang.Double#toString(double) |
769 |
*/ |
|
770 |
public void print(double d) { |
|
771 |
write(String.valueOf(d)); |
|
772 |
} |
|
773 |
||
774 |
/** |
|
775 |
* Prints an array of characters. The characters are converted into bytes |
|
55727 | 776 |
* according to the character encoding given to the constructor, or the |
777 |
* platform's default character encoding if none specified. These bytes |
|
778 |
* are written in exactly the manner of the {@link #write(int)} method. |
|
2 | 779 |
* |
780 |
* @param s The array of chars to be printed |
|
781 |
* |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
782 |
* @throws NullPointerException If {@code s} is {@code null} |
2 | 783 |
*/ |
784 |
public void print(char s[]) { |
|
785 |
write(s); |
|
786 |
} |
|
787 |
||
788 |
/** |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
789 |
* Prints a string. If the argument is {@code null} then the string |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
790 |
* {@code "null"} is printed. Otherwise, the string's characters are |
55727 | 791 |
* converted into bytes according to the character encoding given to the |
792 |
* constructor, or the platform's default character encoding if none |
|
793 |
* specified. These bytes are written in exactly the manner of the |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
794 |
* {@link #write(int)} method. |
2 | 795 |
* |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
796 |
* @param s The {@code String} to be printed |
2 | 797 |
*/ |
798 |
public void print(String s) { |
|
40410 | 799 |
write(String.valueOf(s)); |
2 | 800 |
} |
801 |
||
802 |
/** |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
803 |
* Prints an object. The string produced by the {@link |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
804 |
* java.lang.String#valueOf(Object)} method is translated into bytes |
2 | 805 |
* according to the platform's default character encoding, and these bytes |
806 |
* are written in exactly the manner of the |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
807 |
* {@link #write(int)} method. |
2 | 808 |
* |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
809 |
* @param obj The {@code Object} to be printed |
2 | 810 |
* @see java.lang.Object#toString() |
811 |
*/ |
|
812 |
public void print(Object obj) { |
|
813 |
write(String.valueOf(obj)); |
|
814 |
} |
|
815 |
||
816 |
||
817 |
/* Methods that do terminate lines */ |
|
818 |
||
819 |
/** |
|
820 |
* Terminates the current line by writing the line separator string. The |
|
821 |
* line separator string is defined by the system property |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
822 |
* {@code line.separator}, and is not necessarily a single newline |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
823 |
* character ({@code '\n'}). |
2 | 824 |
*/ |
825 |
public void println() { |
|
826 |
newLine(); |
|
827 |
} |
|
828 |
||
829 |
/** |
|
830 |
* Prints a boolean and then terminate the line. This method behaves as |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
831 |
* though it invokes {@link #print(boolean)} and then |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
832 |
* {@link #println()}. |
2 | 833 |
* |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
834 |
* @param x The {@code boolean} to be printed |
2 | 835 |
*/ |
836 |
public void println(boolean x) { |
|
53148 | 837 |
if (getClass() == PrintStream.class) { |
838 |
writeln(String.valueOf(x)); |
|
839 |
} else { |
|
840 |
synchronized (this) { |
|
841 |
print(x); |
|
842 |
newLine(); |
|
843 |
} |
|
2 | 844 |
} |
845 |
} |
|
846 |
||
847 |
/** |
|
848 |
* Prints a character and then terminate the line. This method behaves as |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
849 |
* though it invokes {@link #print(char)} and then |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
850 |
* {@link #println()}. |
2 | 851 |
* |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
852 |
* @param x The {@code char} to be printed. |
2 | 853 |
*/ |
854 |
public void println(char x) { |
|
53148 | 855 |
if (getClass() == PrintStream.class) { |
856 |
writeln(String.valueOf(x)); |
|
857 |
} else { |
|
858 |
synchronized (this) { |
|
859 |
print(x); |
|
860 |
newLine(); |
|
861 |
} |
|
2 | 862 |
} |
863 |
} |
|
864 |
||
865 |
/** |
|
866 |
* Prints an integer and then terminate the line. This method behaves as |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
867 |
* though it invokes {@link #print(int)} and then |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
868 |
* {@link #println()}. |
2 | 869 |
* |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
870 |
* @param x The {@code int} to be printed. |
2 | 871 |
*/ |
872 |
public void println(int x) { |
|
53148 | 873 |
if (getClass() == PrintStream.class) { |
874 |
writeln(String.valueOf(x)); |
|
875 |
} else { |
|
876 |
synchronized (this) { |
|
877 |
print(x); |
|
878 |
newLine(); |
|
879 |
} |
|
2 | 880 |
} |
881 |
} |
|
882 |
||
883 |
/** |
|
884 |
* Prints a long and then terminate the line. This method behaves as |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
885 |
* though it invokes {@link #print(long)} and then |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
886 |
* {@link #println()}. |
2 | 887 |
* |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
888 |
* @param x a The {@code long} to be printed. |
2 | 889 |
*/ |
890 |
public void println(long x) { |
|
53148 | 891 |
if (getClass() == PrintStream.class) { |
892 |
writeln(String.valueOf(x)); |
|
893 |
} else { |
|
894 |
synchronized (this) { |
|
895 |
print(x); |
|
896 |
newLine(); |
|
897 |
} |
|
2 | 898 |
} |
899 |
} |
|
900 |
||
901 |
/** |
|
902 |
* Prints a float and then terminate the line. This method behaves as |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
903 |
* though it invokes {@link #print(float)} and then |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
904 |
* {@link #println()}. |
2 | 905 |
* |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
906 |
* @param x The {@code float} to be printed. |
2 | 907 |
*/ |
908 |
public void println(float x) { |
|
53148 | 909 |
if (getClass() == PrintStream.class) { |
910 |
writeln(String.valueOf(x)); |
|
911 |
} else { |
|
912 |
synchronized (this) { |
|
913 |
print(x); |
|
914 |
newLine(); |
|
915 |
} |
|
2 | 916 |
} |
917 |
} |
|
918 |
||
919 |
/** |
|
920 |
* Prints a double and then terminate the line. This method behaves as |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
921 |
* though it invokes {@link #print(double)} and then |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
922 |
* {@link #println()}. |
2 | 923 |
* |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
924 |
* @param x The {@code double} to be printed. |
2 | 925 |
*/ |
926 |
public void println(double x) { |
|
53148 | 927 |
if (getClass() == PrintStream.class) { |
928 |
writeln(String.valueOf(x)); |
|
929 |
} else { |
|
930 |
synchronized (this) { |
|
931 |
print(x); |
|
932 |
newLine(); |
|
933 |
} |
|
2 | 934 |
} |
935 |
} |
|
936 |
||
937 |
/** |
|
938 |
* Prints an array of characters and then terminate the line. This method |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
939 |
* behaves as though it invokes {@link #print(char[])} and |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
940 |
* then {@link #println()}. |
2 | 941 |
* |
942 |
* @param x an array of chars to print. |
|
943 |
*/ |
|
53148 | 944 |
public void println(char[] x) { |
945 |
if (getClass() == PrintStream.class) { |
|
946 |
writeln(x); |
|
947 |
} else { |
|
948 |
synchronized (this) { |
|
949 |
print(x); |
|
950 |
newLine(); |
|
951 |
} |
|
2 | 952 |
} |
953 |
} |
|
954 |
||
955 |
/** |
|
956 |
* Prints a String and then terminate the line. This method behaves as |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
957 |
* though it invokes {@link #print(String)} and then |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
958 |
* {@link #println()}. |
2 | 959 |
* |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
960 |
* @param x The {@code String} to be printed. |
2 | 961 |
*/ |
962 |
public void println(String x) { |
|
53148 | 963 |
if (getClass() == PrintStream.class) { |
964 |
writeln(String.valueOf(x)); |
|
965 |
} else { |
|
966 |
synchronized (this) { |
|
967 |
print(x); |
|
968 |
newLine(); |
|
969 |
} |
|
2 | 970 |
} |
971 |
} |
|
972 |
||
973 |
/** |
|
974 |
* Prints an Object and then terminate the line. This method calls |
|
975 |
* at first String.valueOf(x) to get the printed object's string value, |
|
976 |
* then behaves as |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
977 |
* though it invokes {@link #print(String)} and then |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
978 |
* {@link #println()}. |
2 | 979 |
* |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
980 |
* @param x The {@code Object} to be printed. |
2 | 981 |
*/ |
982 |
public void println(Object x) { |
|
983 |
String s = String.valueOf(x); |
|
53148 | 984 |
if (getClass() == PrintStream.class) { |
985 |
// need to apply String.valueOf again since first invocation |
|
986 |
// might return null |
|
987 |
writeln(String.valueOf(s)); |
|
988 |
} else { |
|
989 |
synchronized (this) { |
|
990 |
print(s); |
|
991 |
newLine(); |
|
992 |
} |
|
2 | 993 |
} |
994 |
} |
|
995 |
||
996 |
||
997 |
/** |
|
998 |
* A convenience method to write a formatted string to this output stream |
|
999 |
* using the specified format string and arguments. |
|
1000 |
* |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1001 |
* <p> An invocation of this method of the form |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1002 |
* {@code out.printf(format, args)} behaves |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1003 |
* in exactly the same way as the invocation |
2 | 1004 |
* |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1005 |
* <pre>{@code |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1006 |
* out.format(format, args) |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1007 |
* }</pre> |
2 | 1008 |
* |
1009 |
* @param format |
|
1010 |
* A format string as described in <a |
|
1011 |
* href="../util/Formatter.html#syntax">Format string syntax</a> |
|
1012 |
* |
|
1013 |
* @param args |
|
1014 |
* Arguments referenced by the format specifiers in the format |
|
1015 |
* string. If there are more arguments than format specifiers, the |
|
1016 |
* extra arguments are ignored. The number of arguments is |
|
1017 |
* variable and may be zero. The maximum number of arguments is |
|
1018 |
* limited by the maximum dimension of a Java array as defined by |
|
9266
121fb370f179
7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents:
8166
diff
changeset
|
1019 |
* <cite>The Java™ Virtual Machine Specification</cite>. |
121fb370f179
7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents:
8166
diff
changeset
|
1020 |
* The behaviour on a |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1021 |
* {@code null} argument depends on the <a |
2 | 1022 |
* href="../util/Formatter.html#syntax">conversion</a>. |
1023 |
* |
|
18156 | 1024 |
* @throws java.util.IllegalFormatException |
2 | 1025 |
* If a format string contains an illegal syntax, a format |
1026 |
* specifier that is incompatible with the given arguments, |
|
1027 |
* insufficient arguments given the format string, or other |
|
1028 |
* illegal conditions. For specification of all possible |
|
1029 |
* formatting errors, see the <a |
|
1030 |
* href="../util/Formatter.html#detail">Details</a> section of the |
|
1031 |
* formatter class specification. |
|
1032 |
* |
|
1033 |
* @throws NullPointerException |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1034 |
* If the {@code format} is {@code null} |
2 | 1035 |
* |
1036 |
* @return This output stream |
|
1037 |
* |
|
1038 |
* @since 1.5 |
|
1039 |
*/ |
|
1040 |
public PrintStream printf(String format, Object ... args) { |
|
1041 |
return format(format, args); |
|
1042 |
} |
|
1043 |
||
1044 |
/** |
|
1045 |
* A convenience method to write a formatted string to this output stream |
|
1046 |
* using the specified format string and arguments. |
|
1047 |
* |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1048 |
* <p> An invocation of this method of the form |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1049 |
* {@code out.printf(l, format, args)} behaves |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1050 |
* in exactly the same way as the invocation |
2 | 1051 |
* |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1052 |
* <pre>{@code |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1053 |
* out.format(l, format, args) |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1054 |
* }</pre> |
2 | 1055 |
* |
1056 |
* @param l |
|
1057 |
* The {@linkplain java.util.Locale locale} to apply during |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1058 |
* formatting. If {@code l} is {@code null} then no localization |
2 | 1059 |
* is applied. |
1060 |
* |
|
1061 |
* @param format |
|
1062 |
* A format string as described in <a |
|
1063 |
* href="../util/Formatter.html#syntax">Format string syntax</a> |
|
1064 |
* |
|
1065 |
* @param args |
|
1066 |
* Arguments referenced by the format specifiers in the format |
|
1067 |
* string. If there are more arguments than format specifiers, the |
|
1068 |
* extra arguments are ignored. The number of arguments is |
|
1069 |
* variable and may be zero. The maximum number of arguments is |
|
1070 |
* limited by the maximum dimension of a Java array as defined by |
|
9266
121fb370f179
7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents:
8166
diff
changeset
|
1071 |
* <cite>The Java™ Virtual Machine Specification</cite>. |
121fb370f179
7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents:
8166
diff
changeset
|
1072 |
* The behaviour on a |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1073 |
* {@code null} argument depends on the <a |
2 | 1074 |
* href="../util/Formatter.html#syntax">conversion</a>. |
1075 |
* |
|
18156 | 1076 |
* @throws java.util.IllegalFormatException |
2 | 1077 |
* If a format string contains an illegal syntax, a format |
1078 |
* specifier that is incompatible with the given arguments, |
|
1079 |
* insufficient arguments given the format string, or other |
|
1080 |
* illegal conditions. For specification of all possible |
|
1081 |
* formatting errors, see the <a |
|
1082 |
* href="../util/Formatter.html#detail">Details</a> section of the |
|
1083 |
* formatter class specification. |
|
1084 |
* |
|
1085 |
* @throws NullPointerException |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1086 |
* If the {@code format} is {@code null} |
2 | 1087 |
* |
1088 |
* @return This output stream |
|
1089 |
* |
|
1090 |
* @since 1.5 |
|
1091 |
*/ |
|
1092 |
public PrintStream printf(Locale l, String format, Object ... args) { |
|
1093 |
return format(l, format, args); |
|
1094 |
} |
|
1095 |
||
1096 |
/** |
|
1097 |
* Writes a formatted string to this output stream using the specified |
|
1098 |
* format string and arguments. |
|
1099 |
* |
|
1100 |
* <p> The locale always used is the one returned by {@link |
|
38786
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
32033
diff
changeset
|
1101 |
* java.util.Locale#getDefault(Locale.Category)} with |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
32033
diff
changeset
|
1102 |
* {@link java.util.Locale.Category#FORMAT FORMAT} category specified, |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
32033
diff
changeset
|
1103 |
* regardless of any previous invocations of other formatting methods on |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
32033
diff
changeset
|
1104 |
* this object. |
2 | 1105 |
* |
1106 |
* @param format |
|
1107 |
* A format string as described in <a |
|
1108 |
* href="../util/Formatter.html#syntax">Format string syntax</a> |
|
1109 |
* |
|
1110 |
* @param args |
|
1111 |
* Arguments referenced by the format specifiers in the format |
|
1112 |
* string. If there are more arguments than format specifiers, the |
|
1113 |
* extra arguments are ignored. The number of arguments is |
|
1114 |
* variable and may be zero. The maximum number of arguments is |
|
1115 |
* limited by the maximum dimension of a Java array as defined by |
|
9266
121fb370f179
7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents:
8166
diff
changeset
|
1116 |
* <cite>The Java™ Virtual Machine Specification</cite>. |
121fb370f179
7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents:
8166
diff
changeset
|
1117 |
* The behaviour on a |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1118 |
* {@code null} argument depends on the <a |
2 | 1119 |
* href="../util/Formatter.html#syntax">conversion</a>. |
1120 |
* |
|
18156 | 1121 |
* @throws java.util.IllegalFormatException |
2 | 1122 |
* If a format string contains an illegal syntax, a format |
1123 |
* specifier that is incompatible with the given arguments, |
|
1124 |
* insufficient arguments given the format string, or other |
|
1125 |
* illegal conditions. For specification of all possible |
|
1126 |
* formatting errors, see the <a |
|
1127 |
* href="../util/Formatter.html#detail">Details</a> section of the |
|
1128 |
* formatter class specification. |
|
1129 |
* |
|
1130 |
* @throws NullPointerException |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1131 |
* If the {@code format} is {@code null} |
2 | 1132 |
* |
1133 |
* @return This output stream |
|
1134 |
* |
|
1135 |
* @since 1.5 |
|
1136 |
*/ |
|
1137 |
public PrintStream format(String format, Object ... args) { |
|
1138 |
try { |
|
1139 |
synchronized (this) { |
|
1140 |
ensureOpen(); |
|
1141 |
if ((formatter == null) |
|
38786
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
32033
diff
changeset
|
1142 |
|| (formatter.locale() != |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
32033
diff
changeset
|
1143 |
Locale.getDefault(Locale.Category.FORMAT))) |
2 | 1144 |
formatter = new Formatter((Appendable) this); |
38786
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
32033
diff
changeset
|
1145 |
formatter.format(Locale.getDefault(Locale.Category.FORMAT), |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
32033
diff
changeset
|
1146 |
format, args); |
2 | 1147 |
} |
1148 |
} catch (InterruptedIOException x) { |
|
1149 |
Thread.currentThread().interrupt(); |
|
1150 |
} catch (IOException x) { |
|
1151 |
trouble = true; |
|
1152 |
} |
|
1153 |
return this; |
|
1154 |
} |
|
1155 |
||
1156 |
/** |
|
1157 |
* Writes a formatted string to this output stream using the specified |
|
1158 |
* format string and arguments. |
|
1159 |
* |
|
1160 |
* @param l |
|
1161 |
* The {@linkplain java.util.Locale locale} to apply during |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1162 |
* formatting. If {@code l} is {@code null} then no localization |
2 | 1163 |
* is applied. |
1164 |
* |
|
1165 |
* @param format |
|
1166 |
* A format string as described in <a |
|
1167 |
* href="../util/Formatter.html#syntax">Format string syntax</a> |
|
1168 |
* |
|
1169 |
* @param args |
|
1170 |
* Arguments referenced by the format specifiers in the format |
|
1171 |
* string. If there are more arguments than format specifiers, the |
|
1172 |
* extra arguments are ignored. The number of arguments is |
|
1173 |
* variable and may be zero. The maximum number of arguments is |
|
1174 |
* limited by the maximum dimension of a Java array as defined by |
|
9266
121fb370f179
7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents:
8166
diff
changeset
|
1175 |
* <cite>The Java™ Virtual Machine Specification</cite>. |
121fb370f179
7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents:
8166
diff
changeset
|
1176 |
* The behaviour on a |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1177 |
* {@code null} argument depends on the <a |
2 | 1178 |
* href="../util/Formatter.html#syntax">conversion</a>. |
1179 |
* |
|
18156 | 1180 |
* @throws java.util.IllegalFormatException |
2 | 1181 |
* If a format string contains an illegal syntax, a format |
1182 |
* specifier that is incompatible with the given arguments, |
|
1183 |
* insufficient arguments given the format string, or other |
|
1184 |
* illegal conditions. For specification of all possible |
|
1185 |
* formatting errors, see the <a |
|
1186 |
* href="../util/Formatter.html#detail">Details</a> section of the |
|
1187 |
* formatter class specification. |
|
1188 |
* |
|
1189 |
* @throws NullPointerException |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1190 |
* If the {@code format} is {@code null} |
2 | 1191 |
* |
1192 |
* @return This output stream |
|
1193 |
* |
|
1194 |
* @since 1.5 |
|
1195 |
*/ |
|
1196 |
public PrintStream format(Locale l, String format, Object ... args) { |
|
1197 |
try { |
|
1198 |
synchronized (this) { |
|
1199 |
ensureOpen(); |
|
1200 |
if ((formatter == null) |
|
1201 |
|| (formatter.locale() != l)) |
|
1202 |
formatter = new Formatter(this, l); |
|
1203 |
formatter.format(l, format, args); |
|
1204 |
} |
|
1205 |
} catch (InterruptedIOException x) { |
|
1206 |
Thread.currentThread().interrupt(); |
|
1207 |
} catch (IOException x) { |
|
1208 |
trouble = true; |
|
1209 |
} |
|
1210 |
return this; |
|
1211 |
} |
|
1212 |
||
1213 |
/** |
|
1214 |
* Appends the specified character sequence to this output stream. |
|
1215 |
* |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1216 |
* <p> An invocation of this method of the form {@code out.append(csq)} |
2 | 1217 |
* behaves in exactly the same way as the invocation |
1218 |
* |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1219 |
* <pre>{@code |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1220 |
* out.print(csq.toString()) |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1221 |
* }</pre> |
2 | 1222 |
* |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1223 |
* <p> Depending on the specification of {@code toString} for the |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1224 |
* character sequence {@code csq}, the entire sequence may not be |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1225 |
* appended. For instance, invoking then {@code toString} method of a |
2 | 1226 |
* character buffer will return a subsequence whose content depends upon |
1227 |
* the buffer's position and limit. |
|
1228 |
* |
|
1229 |
* @param csq |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1230 |
* The character sequence to append. If {@code csq} is |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1231 |
* {@code null}, then the four characters {@code "null"} are |
2 | 1232 |
* appended to this output stream. |
1233 |
* |
|
1234 |
* @return This output stream |
|
1235 |
* |
|
1236 |
* @since 1.5 |
|
1237 |
*/ |
|
1238 |
public PrintStream append(CharSequence csq) { |
|
40410 | 1239 |
print(String.valueOf(csq)); |
2 | 1240 |
return this; |
1241 |
} |
|
1242 |
||
1243 |
/** |
|
1244 |
* Appends a subsequence of the specified character sequence to this output |
|
1245 |
* stream. |
|
1246 |
* |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1247 |
* <p> An invocation of this method of the form |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1248 |
* {@code out.append(csq, start, end)} when |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1249 |
* {@code csq} is not {@code null}, behaves in |
2 | 1250 |
* exactly the same way as the invocation |
1251 |
* |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1252 |
* <pre>{@code |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1253 |
* out.print(csq.subSequence(start, end).toString()) |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1254 |
* }</pre> |
2 | 1255 |
* |
1256 |
* @param csq |
|
1257 |
* The character sequence from which a subsequence will be |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1258 |
* appended. If {@code csq} is {@code null}, then characters |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1259 |
* will be appended as if {@code csq} contained the four |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1260 |
* characters {@code "null"}. |
2 | 1261 |
* |
1262 |
* @param start |
|
1263 |
* The index of the first character in the subsequence |
|
1264 |
* |
|
1265 |
* @param end |
|
1266 |
* The index of the character following the last character in the |
|
1267 |
* subsequence |
|
1268 |
* |
|
1269 |
* @return This output stream |
|
1270 |
* |
|
1271 |
* @throws IndexOutOfBoundsException |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1272 |
* If {@code start} or {@code end} are negative, {@code start} |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1273 |
* is greater than {@code end}, or {@code end} is greater than |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1274 |
* {@code csq.length()} |
2 | 1275 |
* |
1276 |
* @since 1.5 |
|
1277 |
*/ |
|
1278 |
public PrintStream append(CharSequence csq, int start, int end) { |
|
40410 | 1279 |
if (csq == null) csq = "null"; |
1280 |
return append(csq.subSequence(start, end)); |
|
2 | 1281 |
} |
1282 |
||
1283 |
/** |
|
1284 |
* Appends the specified character to this output stream. |
|
1285 |
* |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1286 |
* <p> An invocation of this method of the form {@code out.append(c)} |
2 | 1287 |
* behaves in exactly the same way as the invocation |
1288 |
* |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1289 |
* <pre>{@code |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1290 |
* out.print(c) |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
25859
diff
changeset
|
1291 |
* }</pre> |
2 | 1292 |
* |
1293 |
* @param c |
|
1294 |
* The 16-bit character to append |
|
1295 |
* |
|
1296 |
* @return This output stream |
|
1297 |
* |
|
1298 |
* @since 1.5 |
|
1299 |
*/ |
|
1300 |
public PrintStream append(char c) { |
|
1301 |
print(c); |
|
1302 |
return this; |
|
1303 |
} |
|
1304 |
||
1305 |
} |