A DESCRIPTION OF THE REQUEST :
Handling of a PrintWriters line.separator string is awkard when dealing with multiple streams with different conventions.
Currently, the line separator is fetched from the system properties in the constructer, and used for subsequently.
In order to use a specific convention for a certain writer, the system properites must be manipulated, which is awkward.
However, the .format() method does not use the PrintWriters internal variable but instead uses the system parameter, the first time it is needed.
JUSTIFICATION :
The printwriter.format("%") does not work as expected, as it does not follow the convention of printwriter.println() if the system property "line.separator" is modified.
It is awkard to manipulate the system properties in order to configure a printwriter, if writing different types of files.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
PrintWriter should accept a line separator string as a constructor argument .
The line separator string should be passed on to the Formatter used in .format()
ACTUAL -
PrintWriter uses the current system property "line.separator"
The Formatter used in pw.format() uses a pontially different line separator system property,
---------- BEGIN SOURCE ----------
import java.io.PrintWriter;
public class Test {
public static void main(String[] args) {
System.setProperty("line.separator", "\n");
PrintWriter pw = new PrintWriter(System.out,true);
pw.println("Hello world.");
System.setProperty("line.separator", "xxx\n");
pw.println("Hello again.");
pw.format("Hello yet another time.%n");
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Need to do:
pw.format("hello");
pw.println();
instead of
pw.format("hello%n");
Which works for simple strings, but is awkward for multi line strings.
Handling of a PrintWriters line.separator string is awkard when dealing with multiple streams with different conventions.
Currently, the line separator is fetched from the system properties in the constructer, and used for subsequently.
In order to use a specific convention for a certain writer, the system properites must be manipulated, which is awkward.
However, the .format() method does not use the PrintWriters internal variable but instead uses the system parameter, the first time it is needed.
JUSTIFICATION :
The printwriter.format("%") does not work as expected, as it does not follow the convention of printwriter.println() if the system property "line.separator" is modified.
It is awkard to manipulate the system properties in order to configure a printwriter, if writing different types of files.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
PrintWriter should accept a line separator string as a constructor argument .
The line separator string should be passed on to the Formatter used in .format()
ACTUAL -
PrintWriter uses the current system property "line.separator"
The Formatter used in pw.format() uses a pontially different line separator system property,
---------- BEGIN SOURCE ----------
import java.io.PrintWriter;
public class Test {
public static void main(String[] args) {
System.setProperty("line.separator", "\n");
PrintWriter pw = new PrintWriter(System.out,true);
pw.println("Hello world.");
System.setProperty("line.separator", "xxx\n");
pw.println("Hello again.");
pw.format("Hello yet another time.%n");
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Need to do:
pw.format("hello");
pw.println();
instead of
pw.format("hello%n");
Which works for simple strings, but is awkward for multi line strings.
- relates to
-
JDK-8068498 Remove constructor dependency on line.separator from PrintWriter and BufferedWriter
-
- Resolved
-