OpenJDK / jdk7 / jdk7 / jdk
changeset 1960:0dcdb13ab6d0
6900043: Add method to return line.separator property
Summary: Add System.lineSeparator(), returning getProperty("line.separator")
Reviewed-by: darcy
author | martin |
---|---|
date | Mon, 07 Dec 2009 16:44:40 -0800 |
parents | e47e55b6ecf6 |
children | 146c8921267f |
files | src/share/classes/java/lang/System.java src/share/classes/java/util/Formatter.java |
diffstat | 2 files changed, 17 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/classes/java/lang/System.java Mon Dec 07 15:32:26 2009 -0800 +++ b/src/share/classes/java/lang/System.java Mon Dec 07 16:44:40 2009 -0800 @@ -620,6 +620,20 @@ } /** + * Returns the system-dependent line separator string. It always + * returns the same value - the initial value of the {@linkplain + * #getProperty(String) system property} {@code line.separator}. + * + * <p>On UNIX systems, it returns {@code "\n"}; on Microsoft + * Windows systems it returns {@code "\r\n"}. + */ + public static String lineSeparator() { + return lineSeparator; + } + + private static String lineSeparator; + + /** * Sets the system properties to the <code>Properties</code> * argument. * <p> @@ -1104,6 +1118,7 @@ private static void initializeSystemClass() { props = new Properties(); initProperties(props); + lineSeparator = props.getProperty("line.separator"); sun.misc.Version.init(); // Workaround until DownloadManager initialization is revisited. @@ -1192,7 +1207,7 @@ } /* returns the class of the caller. */ - static Class getCallerClass() { + static Class<?> getCallerClass() { // NOTE use of more generic Reflection.getCallerClass() return Reflection.getCallerClass(3); }
--- a/src/share/classes/java/util/Formatter.java Mon Dec 07 15:32:26 2009 -0800 +++ b/src/share/classes/java/util/Formatter.java Mon Dec 07 16:44:40 2009 -0800 @@ -2552,9 +2552,6 @@ private boolean dt = false; private char c; - // cache the line separator - private String ls; - private int index(String s) { if (s != null) { try { @@ -2702,9 +2699,7 @@ printHashCode(arg); break; case Conversion.LINE_SEPARATOR: - if (ls == null) - ls = System.getProperty("line.separator"); - a.append(ls); + a.append(System.lineSeparator()); break; case Conversion.PERCENT_SIGN: a.append('%');