提交 399c52fb 编写于 作者: M martin

6900043: Add method to return line.separator property

Summary: Add System.lineSeparator(), returning getProperty("line.separator")
Reviewed-by: darcy
上级 caeae0a4
......@@ -619,6 +619,20 @@ public final class System {
return props;
}
/**
* 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.
......@@ -1104,6 +1118,7 @@ public final class System {
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 @@ public final class System {
}
/* returns the class of the caller. */
static Class getCallerClass() {
static Class<?> getCallerClass() {
// NOTE use of more generic Reflection.getCallerClass()
return Reflection.getCallerClass(3);
}
......
......@@ -2552,9 +2552,6 @@ public final class Formatter implements Closeable, Flushable {
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 @@ public final class Formatter implements Closeable, Flushable {
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('%');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册