mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-12 06:29:37 +00:00
6900043: Add method to return line.separator property
Add System.lineSeparator(), returning getProperty("line.separator")
Reviewed-by: darcy
This commit is contained in:
parent
5732731ca5
commit
74ad65ac21
@ -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('%');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user