1010
1111package org .junitpioneer .jupiter ;
1212
13+ import java .io .ByteArrayOutputStream ;
1314import java .io .OutputStream ;
14- import java .io .StringWriter ;
15- import java .nio .charset .Charset ;
1615import java .util .Arrays ;
1716
1817abstract class StdOutputStream extends OutputStream {
1918
20- private final StringWriter writer = new StringWriter ();
19+ private final ByteArrayOutputStream out = new ByteArrayOutputStream ();
2120
2221 public StdOutputStream () {
2322 // recreate default constructor to prevent compiler warning
2423 }
2524
2625 @ Override
2726 public void write (int i ) {
28- writer .write (i );
27+ out .write (i );
2928 }
3029
3130 @ Override
3231 public final void write (byte [] b , int off , int len ) {
33- writer .write (new String ( b , Charset . defaultCharset ()) , off , len );
32+ out .write (b , off , len );
3433 }
3534
3635 /**
3736 * @return the string that was written to {@code System.out} or {@code System.err}
3837 */
3938 public String capturedString () {
40- return writer .toString ();
39+ return out .toString ();
4140 }
4241
4342 /**
@@ -55,7 +54,7 @@ public String capturedString() {
5554 * @return the lines that were written to {@code System.out} or {@code System.err}
5655 */
5756 public String [] capturedLines () {
58- var lines = writer .toString ().split (StdIoExtension .SEPARATOR , -1 );
57+ var lines = out .toString ().split (StdIoExtension .SEPARATOR , -1 );
5958 return lines [lines .length - 1 ].isEmpty () ? Arrays .copyOf (lines , lines .length - 1 ) : lines ;
6059 }
6160
0 commit comments