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