Skip to content

Commit 78bb66b

Browse files
committed
Reduce flushes in FormHttpMessageConverter
Before this commit, each part written by the FormHttpMessageConverter would typically end with a flush, which reduced performance.
1 parent 2461353 commit 78bb66b

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.http.converter;
1818

19+
import java.io.FilterOutputStream;
1920
import java.io.IOException;
2021
import java.io.OutputStream;
2122
import java.net.URLDecoder;
@@ -618,7 +619,7 @@ private static class MultipartHttpOutputMessage implements HttpOutputMessage {
618619
private boolean headersWritten = false;
619620

620621
public MultipartHttpOutputMessage(OutputStream outputStream, Charset charset) {
621-
this.outputStream = outputStream;
622+
this.outputStream = new MultipartOutputStream(outputStream);
622623
this.charset = charset;
623624
}
624625

@@ -654,6 +655,32 @@ private void writeHeaders() throws IOException {
654655
private byte[] getBytes(String name) {
655656
return name.getBytes(this.charset);
656657
}
658+
659+
}
660+
661+
662+
/**
663+
* OutputStream that neither flushes nor closes.
664+
*/
665+
private static class MultipartOutputStream extends FilterOutputStream {
666+
667+
public MultipartOutputStream(OutputStream out) {
668+
super(out);
669+
}
670+
671+
@Override
672+
public void write(byte[] b, int off, int let) throws IOException {
673+
this.out.write(b, off, let);
674+
}
675+
676+
@Override
677+
public void flush() {
678+
}
679+
680+
@Override
681+
public void close() {
682+
}
657683
}
658684

685+
659686
}

0 commit comments

Comments
 (0)