< prev index next >
src/java.base/share/classes/java/io/PrintWriter.java
Print this page
rev 15365 : imported patch 8163517-Various-cleanup-in-java-io-code
@@ -502,11 +502,11 @@
* #write(int)} method.
*
* @param b The {@code boolean} to be printed
*/
public void print(boolean b) {
- write(b ? "true" : "false");
+ write(String.valueOf(b));
}
/**
* Prints a character. The character is translated into one or more bytes
* according to the platform's default character encoding, and these bytes
@@ -597,14 +597,11 @@
* {@link #write(int)} method.
*
* @param s The {@code String} to be printed
*/
public void print(String s) {
- if (s == null) {
- s = "null";
- }
- write(s);
+ write(String.valueOf(s));
}
/**
* Prints an object. The string produced by the {@link
* java.lang.String#valueOf(Object)} method is translated into bytes
@@ -1003,14 +1000,11 @@
* @return This writer
*
* @since 1.5
*/
public PrintWriter append(CharSequence csq) {
- if (csq == null)
- write("null");
- else
- write(csq.toString());
+ write(String.valueOf(csq));
return this;
}
/**
* Appends a subsequence of the specified character sequence to this writer.
@@ -1045,13 +1039,12 @@
* {@code csq.length()}
*
* @since 1.5
*/
public PrintWriter append(CharSequence csq, int start, int end) {
- CharSequence cs = (csq == null ? "null" : csq);
- write(cs.subSequence(start, end).toString());
- return this;
+ if (csq == null) csq = "null";
+ return append(csq.subSequence(start, end));
}
/**
* Appends the specified character to this writer.
*
< prev index next >