Skip to content

Commit c2488b1

Browse files
author
Dave Syer
committed
Flush output streams in capture
Avoids possible test failures owing to unflushed buffers
1 parent c678be4 commit c2488b1

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

spring-boot/src/test/java/org/springframework/boot/OutputCapture.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,19 @@ protected void releaseOutput() {
7272
this.copy = null;
7373
}
7474

75+
public void flush() {
76+
try {
77+
this.captureOut.flush();
78+
this.captureErr.flush();
79+
}
80+
catch (IOException e) {
81+
// ignore
82+
}
83+
}
84+
7585
@Override
7686
public String toString() {
87+
flush();
7788
return this.copy.toString();
7889
}
7990

@@ -104,12 +115,17 @@ public void write(byte[] b) throws IOException {
104115
public void write(byte[] b, int off, int len) throws IOException {
105116
this.copy.write(b, off, len);
106117
this.original.write(b, off, len);
107-
this.original.flush();
108118
}
109119

110120
public PrintStream getOriginal() {
111121
return this.original;
112122
}
123+
124+
@Override
125+
public void flush() throws IOException {
126+
this.copy.flush();
127+
this.original.flush();
128+
}
113129
}
114130

115131
/**

0 commit comments

Comments
 (0)