Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8317425

PrintStream does not allow the line separator to be overridden

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      Duplicate of https://bugs.java.com/bugdatabase/view_bug?bug_id=8294410
      with source code to reproduce.


      ---------- BEGIN SOURCE ----------
      public class Main {

          public static void main(String[] args) throws java.io.IOException {
           System.out.println("First separator's length = " + System.getProperty("line.separator").length() + ".");
           System.out.print("First multiline string will be small. It's length = ");
           System.out.println(getString().length() + ".");
           System.out.println();
          
           System.setProperty("line.separator", "e".repeat(100));
           System.out.println("Second separator's length = " + System.getProperty("line.separator").length() + ".");
           System.out.print("Second multiline string should be huge. It's length = ");
           System.out.println(getString().length() + ".");
          }
          
          public static String getString() throws java.io.IOException {
           try (java.io.PipedOutputStream pipeOut = new java.io.PipedOutputStream();
           java.io.PipedInputStream pipeIn = new java.io.PipedInputStream();
           java.io.PrintStream outputStream = new java.io.PrintStream(pipeOut);
           ) {
           pipeOut.connect(pipeIn);
           outputStream.println("q");
           outputStream.println("w");
           outputStream.close();

           return new String(pipeIn.readAllBytes());
           }
          }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


            tongwan Andrew Wang
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: